How to select datas that doesnt match in another column

后端 未结 6 1429
花落未央
花落未央 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:42

    This query returns all the IDs where the COLOR is red or blue but not both.

    select id , color
    from  your_table 
    where color in ('red', 'blue')
    and id in (
        select id 
        from   your_table 
        where color in ('red', 'blue')
        group by id 
        having count(*) = 1) 
    

提交回复
热议问题