我正在寻找“练习和游戏”表中不存在的条目,但是我无法使用第二个不在声明中。还有其他方法吗?

 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

10-08 06:50