我有一个查询,简化为:
SELECT
`table1`.`col`,
`table2`.`col`,
`table3`.`col`,
FROM
`table1`,
`table2`,
`table3`
WHERE
`table1`.`col` = `table2`.`col` AND
`table2`.`col` = `table3`.`col` AND
`table3`.`col` = 'x'
除了在table2.col
没有匹配table3.col
即使table2
没有任何匹配数据,我如何调整查询以显示其他两个表中的数据。
答案 0 :(得分:2)
按原样,您无法进行更改a->b->c
加入。如果b
中没有匹配的记录,那么c
中的任何匹配记录都可能不存在。
不知道您的表结构/关系是什么,但是如果您将连接重写为
a->b
a->c
然后即使c
中没有任何内容,您也可以获得b
条记录:
SELECT *
FROM a
LEFT JOIN b ON a.col = c.col // note: joining a->b
LEFT JOIN c ON a.col = c.col // note: joining a->c