How to select datas that doesnt match in another column

后端 未结 6 1432
花落未央
花落未央 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-24 00:05

    Removed the previous answer. Tested this and it is working.

    WITH tbl
    AS (SELECT
      color,
      id
    FROM TABLE1
    WHERE color IN ('red', 'blue')
    )
    SELECT
      t1.color,
      t1.id
    FROM tbl t1
    LEFT JOIN tbl t2
      ON t1.id = t2.id
      AND t1.color <> t2.color
    WHERE t1.id IS NULL
    OR t2.id IS NULL
    

提交回复
热议问题