例 -
select * from discussion where title like '%india%'
UNION
select * from discussion where title like '%Australia%'
両方のタイプの結果を混合したディスカッションIDの順序で結果が表示されます
最初にインドの結果を表示し、次にオーストラリアの結果を表示したいのですが、重複する行も削除する必要があるため、オプションAL1を使用できません。
何をすべきですか?
例 -
select * from discussion where title like '%india%'
UNION
select * from discussion where title like '%Australia%'
両方のタイプの結果を混合したディスカッションIDの順序で結果が表示されます
最初にインドの結果を表示し、次にオーストラリアの結果を表示したいのですが、重複する行も削除する必要があるため、オプションAL1を使用できません。
何をすべきですか?
注文する列を追加できます
select *, 1 as ORD from discussion where title like '%india%'
UNION
select *, 2 as ORD from discussion where title like '%Australia%'
order by ORD
編集-2010年11月29日
ORDの問題が重複しているため、これを達成するためのよりエレガントな方法を考えていました。
Select * from discussion
where title like '%india%' or title like '%Australia%'
order by (case when title like '%india%'then 1 else 2 end)
試す:
SELECT * FROM
(
select 1 OrderNo, d.* from discussion d where title like '%india%'
UNION
select 2 OrderNo, d.* from discussion d where title like '%Australia%'
)
ORder by OrderNo
select * from
(
select * from discussion where title like '%india%'
UNION
select * from discussion where title like '%Australia%'
)
ORDER BY title DESC
;