How to select datas that doesnt match in another column

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

So i have this table A:

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


        
6条回答
  •  Happy的楠姐
    2021-01-23 23:50

    or using an anti join

    select t1.color, t1.id 
    from 
        tableA t1
    left outer join 
         tableA t2 on t2.id = t1.id and t2.color != t1.color 
    where 
     t1.color in ('red', 'blue')
    and t2.color is null
    

提交回复
热议问题