[英]mysql complex select, left join
I have 3 tables, a,b,c 我有3张桌子,a,b,c
It is possible to add left join for two table select add 3rd table by left join: 可以为两个表添加左联接,然后选择通过左联接添加第三个表:
example: 例:
SELECT * from a,b where a.x=b.x and a.z=b.z and b.y>0
(there I need select only that records where I can found exact matches by that rules) (我只需要选择那些可以根据该规则找到完全匹配的记录)
now I want add some fields from 3rd table, but there are possible situation that 3rd table may not contain data for some table a,b records. 现在我想从第三张表中添加一些字段,但是有可能第三张表可能不包含某些表a,b记录的数据。 As I understand I can use left join ? 据我了解,我可以使用左联接吗?
I How can select something this: 我该如何选择一些东西:
SELECT a.*,b.*, c.Q from a,b where a.x=b.x and a.z=b.z and b.y>0 left join c on a.x=c.x
If you don't like writing INNER JOINs: 如果您不喜欢编写内部联接:
SELECT a.*,b.*, c.Q
FROM (a,b)
LEFT JOIN c
ON a.x=c.x
WHERE a.x=b.x and a.z=b.z and b.y>0
SELECT a.*,b.*, c.Q
FROM a
INNER JOIN b
ON a.x=b.x AND a.z=b.z AND b.y>0
LEFT JOIN c
ON a.x=c.x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.