我有两个 sql 表,我想将它们相互比较以找出不匹配的表。
我有一些有用的东西,但出于某种原因错过了两条记录?
表 flag_content 包含: - 用户身份 - content_id
表topfive_order包含 -nid - 用户标识符
我希望找到 flag_content.content_id 中不存在 topfive_order.nid 的所有记录
我当前的查询是:
select * from flag_content left join topfive_order topfive_order ON flag_content.content_id = topfive_order.nid WHERE topfive_order.nid is null
非常欢迎任何提示或建议。我不太确定我用 left join 做了什么..所以我认为漏网的几条记录与此有关。
最佳答案
翻转联接
SELECT *
FROM topfive_order topfive_order left join flag_content
ON flag_content.content_id = topfive_order.nid
WHERE flag_content.content_id IS NULL
要从 topfive_order
表中查找 flag_content
表中不存在的行,您需要将 topfive_order
放在LEFT JOIN
。
有关各种连接类型的更多信息,请参阅 Wikipedia
关于sql - 比较两个表并发现不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4995364/