gpt4 book ai didi

php - 你如何在 MySQL 中订购 UNION?

转载 作者:太空宇宙 更新时间:2023-11-03 11:11:52 25 4
gpt4 key购买 nike

我想知道,我们如何在基于联合的 mysql_query 中对列表 (DESC) 进行排序,当我们在 PHP/MYSQL 中获取此查询时,我们会得到输出。但我们只是简单地在此查询中输入顺序。

 (SELECT info.id 
FROM info, 1_all
WHERE 1_all.id = info.id and 1_all.table_type = 'disp' AND 1_all.year = '$year' AND info.category IN (1,2,3) AND info.area IN (2,5,6)
GROUP BY resinfo.id )
UNION ALL
(SELECT info.id
FROM info, 2_all
WHERE 2_all.id = info.id and 2_all.table_type = 'disp' AND 2_all.year = '$year' AND info.category IN (1,2,3) AND info.area IN (2,5,6)
GROUP BY info.id)

最佳答案

To use an ORDER BY or LIMIT clause to sort or limit the entire UNION result, parenthesize the individual SELECT statements and place the ORDER BY or LIMIT after the last one. The following example uses both clauses:

(SELECT a FROM t1 WHERE a=10 AND B=1)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2)
ORDER BY a LIMIT 10;

http://dev.mysql.com/doc/refman/5.5/en/union.html

关于php - 你如何在 MySQL 中订购 UNION?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7977717/

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