mysql报错1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL

今天有个业务要连表查数据来着。

很久没写SQL了 写完 满意运行


SELECT ac.activity_complaints_id, ac.activity_id, ac.content, ac.complaint_time, u.user_uuid, u.name as userName,  ac.status, a.name as activityName  
FROM t_activity_complaint ac
left JOIN user u ON ac.user_id = u.user_uuid 
left JOIN activity a ON ac.activity_id = a.id
WHERE a.id = 72 
order by ac.complaint_time desc

诶报错 > 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 'WHERE a.id = 72'

mysql报错1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL_第1张图片

不对对这不对对。

然后就开始找原因。

原来是 where 写到order by 前面了

修改后

SELECT ac.activity_complaints_id, ac.activity_id, ac.content, ac.complaint_time, u.user_uuid, u.name as userName,  ac.status, a.name as activityName  
FROM t_activity_complaint ac
left JOIN user u ON ac.user_id = u.user_uuid 
left JOIN activity a ON ac.activity_id = a.id
WHERE a.id = 72 
order by ac.complaint_time desc

再次运行 完美解决。

很多小伙伴可能太久没写SQL 或者 粗心给写错了。

可以看看是不是这个问题。

MySQL的1064错误一般就是sql的语法出错了。仔细检查一下语法,表名和列名都不用加引号

另外还有一个很常见的现象是用到关键字了。错误示范:

select order.* from t_merchant_order order where order_id = #{orderId}

这行sql就是很常见的冲突关键字了 拿order作表t_merchant_order的别名 导致报错。

还有这种 也是会报错的 原因就是查询order表报错

这两种情况我们只需要在order上加``就好了

错误示范:

select * from order

正确示范:

select * from `order`

总的来说 1064错误就是语法问题。大家自己再细心检查一下。感谢观看

你可能感兴趣的:(mysql报错1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL)