mysql - 这条联合sql语句哪里错了
问题描述
((( SELECT a.log_id,`create_date`,`content`,`creator`,`belong_to_user`,a.customer_code,`follow_up_way` FROM gs_log a left join gs_customer b on a.customer_code = b.customer_code WHERE ( b.customer_code != ’’ AND b.customer_id = 2212 ) )) union (( SELECT a.log_id,`create_date`,`content`,`creator`,`belong_to_user`,`customer_code`,`follow_up_way` FROM gs_log a left join gs_r_customer_log on a.log_id = gs_r_customer_log.log_id WHERE ( gs_r_customer_log.customer_id= 2212 ) ))) limit 0,10
这条语句哪里错了,半天没找到,错误提示
[SQL]((( SELECT a.log_id,`create_date`,`content`,`creator`,`belong_to_user`,a.customer_code,`follow_up_way` FROM gs_log a left join gs_customer b on a.customer_code = b.customer_code WHERE ( b.customer_code != ’’ AND b.customer_id = 2212 ) )) union (( SELECT a.log_id,`create_date`,`content`,`creator`,`belong_to_user`,`customer_code`,`follow_up_way` FROM gs_log a left join gs_r_customer_log on a.log_id = gs_r_customer_log.log_id WHERE ( gs_r_customer_log.customer_id= 2212 ) ))) limit 0,10[Err] 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 ’union (( SELECT a.log_id,`create_date`,`content`,`creator`,`belong_to_user`,`cus’ at line 3
问题解答
回答1:你括号加太多了,相当于最外面那层是(...) limit 0,10,只能是(...) union (...) limit 0,10
(( SELECT a.log_id,`create_date`,`content`,`creator`,`belong_to_user`,a.customer_code,`follow_up_way` FROM gs_log a left join gs_customer b on a.customer_code = b.customer_code WHERE ( b.customer_code != ’’ AND b.customer_id = 2212 ) )) union (( SELECT a.log_id,`create_date`,`content`,`creator`,`belong_to_user`,`customer_code`,`follow_up_way` FROM gs_log a left join gs_r_customer_log on a.log_id = gs_r_customer_log.log_id WHERE ( gs_r_customer_log.customer_id= 2212 ) )) limit 0,10回答2:
a.log_id
回答3:建议分步排查。
不知道谁选的答案没帮助?分步排查的意思是将大的SQL语句拆分为多个小SQL语句排查。估计是他没有领悟到。
相关文章:
1. 如何修改phpstudy的phpmyadmin放到其他地方2. php - mysql中,作为主键的字段,用int类型,是不是比用char类型的效率更高?3. tp6表单令牌4. docker 17.03 怎么配置 registry mirror ?5. django - 后台返回的json数据经过Base64加密,获取时用python如何解密~!6. 我的html页面一提交,网页便显示出了我的php代码,求问是什么原因?7. 网络传输协议 - 以下三种下载方式有什么不同?如何用python模拟下载器下载?8. angular.js - Angular路由和express路由的组合使用问题9. 我在centos容器里安装docker,也就是在容器里安装容器,报错了?10. java 排序的问题
