表连接oracle sql中的顺序

时间:2014-04-17 09:21:11

标签: sql oracle join

您是否可以就表格的正确加入顺序提供建议,即4个表格合并我们必须考虑的订单数据。由于我在运行查询时遇到问题,因此出现ORA-00904错误:

select countries.country_name, profits.amount_sold, products.prod_name
from countries
join customers on countries.country_id = customers.country_id
join profits on products.prod_id = profits.prod_id
join profits on profits.cust_id = customers.cust_id
WHERE COUNTRY_NAME = 'India'

1 个答案:

答案 0 :(得分:2)

您要加入profits表两次,而不是加入products表。看起来你的意思是:

select countries.country_name, profits.amount_sold, products.prod_name
from countries
join customers on countries.country_id = customers.country_id
join profits on profits.cust_id = customers.cust_id
join products on products.prod_id = profits.prod_id
WHERE COUNTRY_NAME = 'India'

Oracle将决定加入顺序,但在您加入表之前,您无法引用该表。