[英]MySQL - Sort certain conditions last in the result set (Unions maybe?)
我有一個特定的查詢,我基本上需要獲取具有特定ID的兩行。 起初,我使用where id = x or id = y
。 但是,我需要在結果集中最后獲取第二個參數。 我遇到了UNIONS,我需要知道Union如何對結果進行排序。
工會會幫助實現我想要的嗎?
如果沒有,我如何才能達到預期的效果?
提前致謝。
select *
from your_table
where id in (x, y)
order by id <> x
要么
order by case when id = x then 1 else 2 end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.