MySQL - #1064 - 你的语法有问题 'LIMIT 0, 25'

MySQL - #1064 - Something is wrong in your syntax 'LIMIT 0, 25'

服务器: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 Workbench:

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 决定

  1. 修改我的查询
  2. 抛出不该抛出的错误

让我们找出问题所在 select something from (select 1, 2 as something) limit 123:

#1064 - Something is wrong in your syntax near 'limit 123'

我重启了服务器,还是出现这个错误

select something from (select 1, 2 as something) limit 123

很难确定 1064 的原因,但这是另一个错误——您必须在派生的 table:

上有一个 'alias'
select something from (select 1, 2 as something) AS x limit 123

这个

2 as something

正在给常量取一个别名 2

phpMyAdmin 和 MySQL Workbench 都会自动在您的查询末尾添加“LIMIT”子句,这就是您收到此误导性消息的原因。

但问题的根本原因是您需要为子查询提供别名,例如

select something from (select 1, 2 as something) as t1