我有两个表,一个注册用户和一个存储票。我们正在与registrants.id和registrants.zipcode登录。一旦他们投他们的票插入票表,与他们的注册ID一起。
我试着去正确的返回将选择匹配的ID和邮政编码的所有记录记录的select语句,但ID不在Votes.voter列。我已经尝试了所有种类的所有加入我能想到的变化。是一些简单的我失踪。
SELECT * FROM registrants
LEFT JOIN votes on registrants.id = votes.voter
WHERE registrants.id = 1 AND registrants.zipcode = 46706 and votes.voter <> 1
也许not exists
查询:
select * from registrants
where registrants.zipcode = '46706'
and not exists (select 1 from votes where registrants.id = votes.voter)