【发布时间】:2016-12-12 04:39:48
【问题描述】:
我正在寻找在练习和游戏表中不存在的条目,但是我无法使用第二个 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 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
【讨论】:
您在第二个 not in 中缺少列名(每个条件都是独立的,语法是
select VenueID from Venue
where VenueID not in (select VenueID from Practice)
and VenueID not in (select VenueId from Game)
-- ^^^^^^^
【讨论】: