服务器:MariaDB, version 10.4.17
查询:
select something from (select 1, 2 as something)
phpMyAdmin:中的错误
#1064 - Something is wrong in your syntax 'LIMIT 0, 25'
MySQL工作台错误:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIMIT 0, 1000' at line 2 0.000 sec
好吧,所以MariaDB决定
- 修改我的查询
- 抛出不应该抛出的错误
让我们找出select something from (select 1, 2 as something) limit 123
:的问题
#1064 - Something is wrong in your syntax near 'limit 123'
我重新启动了服务器,但这个错误仍然存在。
phpMyAdmin和MySQL Workbench都会添加"LIMIT";子句自动添加到查询的末尾,这就是您收到此误导性消息的原因。
但问题的根本原因是您需要为子查询提供一个别名,例如
select something from (select 1, 2 as something) as t1
select something from (select 1, 2 as something) limit 123
是模糊的,以确定1064的原因,但这里有另一个错误——派生表上必须有一个"别名":
select something from (select 1, 2 as something) AS x limit 123
这个
2 as something
正在为常量2
提供别名。