SQL: how to use UNION and order by a specific select?

后端 未结 6 2043
不思量自难忘°
不思量自难忘° 2020-12-09 16:18

I have two selects:

SELECT id FROM a -- returns 1,4,2,3
UNION
SELECT id FROM b -- returns 2,1

I\'m receiving correct num of rows, like:

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 16:48

    @Adrian's answer is perfectly suitable, I just wanted to share another way of achieving the same result:

    select nvl(a.id, b.id)
    from a full outer join b on a.id = b.id
    order by b.id;
    

提交回复
热议问题