本文介紹了ORDER BY 和 LIMIT 后的 UNION的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時(shí)送ChatGPT賬號(hào)..
我的目標(biāo)是執(zhí)行兩個(gè)不同的查詢,然后將它們組合起來.
我的代碼是:
My goal is to execute two different queries and then combine them.
My code is:
SELECT * FROM some tables WHERE ... ORDER BY field1 LIMIT 0,1
UNION
SELECT * FROM some tables WHERE ...
我收到以下錯(cuò)誤:
#1221 - UNION 和 ORDER BY 的錯(cuò)誤使用
#1221 - Incorrect usage of UNION and ORDER BY
ORDER BY 僅用于第一個(gè)查詢很重要.我該如何執(zhí)行此任務(wù)?
It is important that ORDER BY is only for the first query. How can I perform this task?
推薦答案
您可以使用括號(hào)來允許對(duì)單個(gè)查詢使用 ORDER
/LIMIT
:
You can use parenthesis to allow the use of ORDER
/LIMIT
on individual queries:
(SELECT * FROM some tables WHERE ... ORDER BY field1 LIMIT 0, 1)
UNION
(SELECT * FROM some tables WHERE ...)
ORDER BY 1 /* optional -- applies to the UNIONed result */
LIMIT 0, 100 /* optional -- applies to the UNIONed result */
這篇關(guān)于ORDER BY 和 LIMIT 后的 UNION的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!