Select records based on column priority

前端 未结 4 1151
Happy的楠姐
Happy的楠姐 2021-01-23 06:37

First of all, the title of this question is horrible, but I didn\'t find a better way to describe my issue.

There\'s probably a very easy way to do this, but I couldn\'t

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 07:30

    Try this

    SELECT * 
    FROM xx
    WHERE COLOUR = 'GREEN'
    UNION
    SELECT * 
    FROM xx WHERE P_Id not in 
                    (SELECT P_Id
                     FROM Persons 
                     WHERE COLOUR = 'GREEN');
    

    See ALSO SQL FIDDLE DEMO

提交回复
热议问题