【问题标题】:Unable to use multiple not in Statements无法在语句中使用多个 not
【发布时间】: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)

【问题讨论】:

    标签: mysql exists notin


    【解决方案1】:

    需要重复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
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2016-11-04
        • 1970-01-01
        • 2014-09-22
        • 2020-08-24
        • 2021-06-25
        • 2017-05-07
        • 1970-01-01
        • 1970-01-01
        • 2019-08-10
        相关资源
        最近更新 更多