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. node.js - vue2 的npm run dev 卡死... 网页无法打开. 8080端口没有被占用...2. javascript - 百度echarts图表如何修改3. 微信无法扫描phpqrcode生成的二维码4. index.php错误,求指点5. vim - docker中新的ubuntu12.04镜像,运行vi提示,找不到命名.6. PHPExcel表格导入数据库怎么导入7. node.js - vue-cll+sass 样式不出来 已经npm install sass、 sass-loader了8. 用PHP怎么在微信公众号里使用模板信息,公众号还未做开发?9. python2.7 - django-redis使用时,连接后,无法访问redis中的数据?10. node.js - win7下用nodejs使用gm出错
