我正在寻找练习和比赛表中不存在的条目,但是我无法使用第二个 not in 语句。还有其他方法可以做到这一点吗?
select VenueID from Venue
where VenueID not in (select VenueID from Practice)
and not in (select VenueId from Game)
最佳答案
您需要重复NOT IN
语句,包括列名称:
SELECT VenueID
FROM Venue
WHERE VenueID NOT IN (SELECT VenueID FROM Practice) AND
VenueID NOT IN (SELECT VenueId FROM Game)
^^^ you omitted the second column name
使用 NOT IN
的一种替代方法是执行两次左连接:
SELECT VenueID
FROM Venue t1
LEFT JOIN Practice t2
ON t1.VenueID = t2.VenueID
LEFT JOIN Game t3
ON t1.VenueID = t3.VenueID
WHERE t2.VenueID IS NULL AND
t3.VenueID IS NULL
关于mysql - 无法在语句中使用多个 not,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41094307/