mysql - 這條聯(lián)合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. python3.x - Python中出現(xiàn)AttributeError: object has no attribute2. javascript - 微信小程序里怎么把頁面轉成圖片分享3. python 多進程 或者 多線程下如何高效的同步數(shù)據(jù)?4. python - flask_Bootstrap的WTF的調用疑問5. 微信端電子書翻頁效果6. mysql - SQL問個基礎例子,書上的,我怎么看都看不懂..誰幫我解釋一下第2個為什么和第1個一樣?7. mysql服務無法啟動1067錯誤,誰知道正確的解決方法?8. mysql事務日志的一些問題9. mysql - 我用SQL語句 更新 行的時候,發(fā)現(xiàn)全部 中文都被清空了,請問怎么解決?10. 數(shù)據(jù)庫 - mysql boolean型無法插入true
