mysql - SQL 查询语法错误,其中语法似乎是正确的

标签 mysql

<分区>

我不知道这个查询有什么问题。这对我来说似乎很好。

select o.id, p.date, u.billingName, u.billingPhone, u.billingCompany,
       u.billingAddress, u.billingCity, u.billingState, u.billingCountry,
       u.billingZip, u.shippingName, u.shippingPhone, u.shippingCompany,
       u.shippingAddress, u.shippingCity, u.shippingState, u.shippingCountry,
       u.shippingZip, o.layer, o.boardSizeWidth,o.boardSizeHeight, o.quantity
from order o, purchase p, useraccount u
where p.id = 1 and o.id = p.OrderId and u.id = p.UserId 

Error : #1064 - 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 'order o, purchase p, useraccount u where p.id = 1 and o.id = p.OrderId and u.id ' at line 1

最佳答案

orderreserved word an 需要使用反引号进行转义。

此外,在连接表时,您还应该使用标准的 ANSI JOIN 语法。请参阅下文了解如何完成此操作。

select ....
from `order` o
inner join purchase p
    on o.id = p.OrderId
inner join useraccount u 
    on u.id = p.UserId
where p.id = 1

作为旁注,您应该避免对表名和列名使用保留字。

关于mysql - SQL 查询语法错误,其中语法似乎是正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15882619/

相关文章:

mysql - 用 git 处理 MySQL 备份是否可行?

php - mysql_unbuffred_query 不工作

database - MySQL 我想进一步优化这个

mysql - 如何在 webform 中打开时锁定 MySQL 资源并在关闭/完成编辑时释放

php - 大 SQL 查询 - 最佳实践

php - 将 json 列转换为 utf8mb4

mysql - SQL - 主键、聚集索引、自动增量

mysql - 尝试连接到 AWS MySQL 实例时 ActiveRecord NoDatabaseError

php - MySQL 变得越来越慢

mysql - 两列之间的时间差 - mysql