我想执行MySQL查询,以便:
SELECT * FROM table_A JOIN table_B on table_A.id = table_B.foreign_key
...但我想返回table_B中table_B中不匹配的行。这可能吗?我怎么能完成它?
答案 0 :(得分:9)
您希望使用LEFT OUTER JOIN
,然后使用WHERE
子句仅允许在连接表上使用NULL。
SELECT * FROM table_A
LEFT OUTER JOIN table_B ON table_A.id = table_B.foreign_key
WHERE table_B.foreign_key IS NULL
答案 1 :(得分:1)
试试这个:
SELECT *
FROM table_A
LEFT JOIN table_B on table_A.id = table_B.foreign_key
WHERE table_B.foreign_key IS NULL