我想执行一个 MySQL 查询,这样:
SELECT * FROM table_A JOIN table_B on table_A.id = table_B.foreign_key
…但我想返回table_B 中与 table_A不匹配的行。这可能吗?我怎样才能实现它?
您想使用 a LEFT OUTER JOIN
and then aWHERE
子句来只允许连接表上的 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
试试这个:
SELECT *
FROM table_A
LEFT JOIN table_B on table_A.id = table_B.foreign_key
WHERE table_B.foreign_key IS NULL