以下查询旨在查找不等于另一个表中相应选民 ID 的记录。
SELECT *
FROM electors,voting_intention
WHERE electors.ID != voting_intention.elector
这应该在这个 FIDDLE 中返回 1 条记录 http://sqlfiddle.com/#!3/0a4b1/10但返回很多并且有重复项。显然我错过了一些东西。什么?
最佳答案
如果您希望获得所有没有任何相应“投票意向”记录的选民,请尝试以下操作。我假设您想要该选民的所有字段。如果没有,您需要选择感兴趣的列。
select * from
electors where id not in
(select elector from voting_intention)
关于PHP mySQL JOIN 判断不相等的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11258638/