如何写一个相当于informix中下面查询的oracle查询:
select tab1.a,tab2.b,tab3.c,tab4.d from table1 tab1,table2 tab2 OUTER (table3 tab3,table4 tab4,table5 tab5) where tab3.xya = tab4.xya AND tab4.ss = tab1.ss AND tab3.dd = tab5.dd AND tab1.fg = tab2.fg AND tab4.kk = tab5.kk AND tab3.desc = "XYZ"
我试过:
select tab1.a,table2 tab2 LEFT OUTER JOIN (table3 tab3,table5 tab5) where tab3.xya = tab4.xya AND tab4.ss = tab1.ss AND tab3.dd = tab5.dd AND tab1.fg = tab2.fg AND tab4.kk = tab5.kk AND tab3.desc = "XYZ"
任何人都可以帮我找到正确的语法.
解决方法
每个连接写一个表,像这样:
select tab1.a,tab4.d from table1 tab1 inner join table2 tab2 on tab2.fg = tab1.fg left join table3 tab3 on tab3.xxx = tab1.xxx left join table4 tab4 on tab4.xya = tab3.xya and tab4.ss = tab3.ss left join table5 tab5 on tab5.dd = tab3.dd and tab5.kk = tab4.kk where tab3.desc = "XYZ"
请注意,当我的查询包含实际的左连接时,您的查询显然不会.由于条件在哪里,您的查询应该像内部连接一样. (虽然我承认我不知道Informix,也许我错了).
如果确实如此,您可以将左连接更改为内部连接.您应该尽可能使用内部连接,因为它们比左侧连接更快.
PS:左连接和左外连接是一样的.