How to select datas that doesnt match in another column

后端 未结 6 1433
花落未央
花落未央 2021-01-23 23:14

So i have this table A:

color        ID       MODEL
-----------------------------
red        | 10   |   HONDA
blue       | 10   |   TOYOTA
red        | 15   |            


        
6条回答
  •  悲&欢浪女
    2021-01-23 23:41

    I think your expected result should just be red 15. Red 30 would not qualify because of yellow 30, which shares the same id. Check out my code:

    SELECT t.id, t.color
    FROM t
    INNER JOIN
    (SELECT id
     FROM t
     GROUP BY id
     HAVING COUNT(*) = 1) sub
    ON t.id = sub.id
    WHERE color = 'red'
    OR color = 'blue'
    

提交回复
热议问题