项目启动报错:
Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax;check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION ALL
要使用ORDER BY
or LIMIT
子句对整个UNION
结果进行排序或限制 ,请在各个SELECT
语句后加上括号,然后将ORDER BY
或 LIMIT
放在最后一个语句之后。
(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;
mysql官方网站的解释如下: