[英]How to select the top n from a union of two queries where the resulting order needs to be ranked by individual query?
[英]How to Order the Results of a Union Query By Which Of The Two Queries Comes From?
基本上我想要這個:
SELECT column FROM Table Where column LIKE "%interesting%"
UNION
SELECT column FROM Table
ORDER BY "the interesting results first, the fillers second."
如果有趣的結果很少,我會這樣做,以便用隨機的結果填充它們。
您只需要一個ORDER BY
:
SELECT column
FROM Table
ORDER BY (CASE WHEN column LIKE '%interesting%' THEN 1 ELSE 2 END);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.