stu*_*stu 4 mysql inner-join outer-join
我可以在sybase中完成它,我可以在oracle中完成它,但我没有看到如何在mysql中完成它.
我有这个:(请限制自己重新格式化我的sql,上次有人这样做,他们改变它,所以它不一样,使问题毫无意义)
select table1.id
from
table1
inner join
table2 on (table1.id = table2.id and table2.data='cat'),
table1 t1
left outer join
table3 on (t1.id = table3.id and table3.data = 'dog')
Run Code Online (Sandbox Code Playgroud)
而且我得到了各种没有意义的结果.
我想得到table1中所有id的列表,其中table2.data = cat,然后对表3执行外连接,其中table3.data = dog.
我注意到我不能在两个join子句中为table1指定相同的表/别名,因此这让我相信mysql分别运行连接表达式并将结果OR运算在一起或类似的东西.
我也尝试摆脱from部分中的"内部联接"并将其放在where子句中,这也不起作用,尽管它不能以不同的方式工作(得到不同的错误结果)
这在sybase或oracle中会非常容易.
我究竟做错了什么?
Sha*_*awn 13
select table1.id
from
table1
inner join
table2 on (table1.id = table2.id and table2.data='cat')
left outer join
table3 on (table1.id = table3.id and table3.data = 'dog')
Run Code Online (Sandbox Code Playgroud)
我想你永远不想在from语句中使用逗号.我相信逗号相当于说交叉连接.虽然不确定,但我认为这个查询是您正在寻找的.
| 归档时间: |
|
| 查看次数: |
10833 次 |
| 最近记录: |