且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL:使用UNION,ORDER BY和LIMIT进行SELECT

更新时间:2023-02-05 11:52:53

这不是它的工作原理,至少在MySQL中(您未指定).在选择数据并执行了所有UNION,GROUP BY等之后,才进行ORDER操作.

That's not how it works, at least in MySQL (you didn't specify). The ORDER operation comes after the data is selected and all UNIONs, GROUP BYs, etc. have been performed.

请参见> SQL Server:在带有UNION的子查询中进行ORDER BY 解决此问题的方法.

See SQL Server: ORDER BY in subquery with UNION for a way around this.