无法在语句中使用多个 not

Unable to use multiple not in Statements

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

 select VenueID from Venue
 where VenueID not in (select VenueID from Practice)
 and not in (select VenueId from Game)

您在第二个 not in 中缺少列名(每个条件都是独立的,语法是 NOT IN ):

select VenueID from Venue
where VenueID not in (select VenueID from Practice)
and VenueID 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