如何解决MySQL - #1064 - 你的语法“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 决定
- 修改我的查询
- 抛出不应该抛出的错误
让我们找出 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
赋予别名。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。