gpt4 book ai didi

jquery - MySql 的 UNION 和 ORDER

转载 作者:行者123 更新时间:2023-11-29 00:10:16 25 4
gpt4 key购买 nike

我使用了以下查询,但显示错误。

SELECT 
id as number,id,parentid,videoid,subject,name,created,message
FROM
umqlh_hdflv_comments
WHERE
`parentid` = '0'
AND `published` = '1'
AND `videoid` = '8'
ORDER BY
number DESC,
parentid
UNION (
SELECT
parentid as number,id,parentid,videoid,subject,name,created,message
FROM
umqlh_hdflv_comments
WHERE
`parentid` != '0'
AND `published` = '1'
AND `videoid` = '8'
)

MySQL 说:文档

#1221 - Incorrect usage of UNION and ORDER BY

我该如何解决?

最佳答案

ORDER BY需要应用在完整的sql语句的末尾,

SELECT 
id as number,
id,
parentid,
videoid,
subject,
name,
created,
message
FROM
umqlh_hdflv_comments
WHERE
`parentid` = '0'
AND `published` = '1'
AND `videoid` = '8'
UNION (
SELECT
parentid as number,
id,
parentid,
videoid,
subject,
name,
created,
message
FROM
umqlh_hdflv_comments
WHERE
`parentid` != '0'
AND `published` = '1'
AND `videoid` = '8'
)
ORDER BY number DESC,parentid

Reference .

关于jquery - MySql 的 UNION 和 ORDER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25521923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com