简体   繁体   English

Oracle SQL中的表连接顺序

[英]Table joining order in oracle sql

Could you give advice on correct joining order for tables ie for 4 tables combining data which order we have to take into consideration. 您能为表格的正确连接顺序提供建议吗,例如4个表格的合并数据,我们必须考虑这些顺序。 As I am having problems in running queries and I am getting an ORA-00904 error: 由于我在运行查询时遇到问题,并且出现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'

You are joining to the profits table twice, and not joining to the products table. 要加入到profits表两次,而不是加入到products表。 Looks like you meant it to be: 看起来您的意思是:

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 will decide the join order, but you can't reference a table before you've joined to it. Oracle将确定连接顺序,但是您无法在连接表之前引用该表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM