MySQL OUTER JOIN syntax error

淺唱寂寞╮ 提交于 2020-04-08 08:40:12

问题


Maybe a facepalm for you guys, but as a SQL query newbie, I'm having a syntax issue. Anyone know what's wrong?

SELECT * FROM company C
OUTER JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL

Giving the 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 
'OUTER JOIN company_address A ON C.company_id = A.company_id WHERE A.address_id 
' at line 2

回答1:


In MySQL you should use LEFT OUTER JOIN or RIGHT OUTER JOIN. There is no just OUTER JOIN. If you need FULL OUTER JOIN in MySql you can use UNION of LEFT JOIN and RIGHT JOIN




回答2:


Try

SELECT * FROM company C
LEFT JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL



回答3:


You have to write LEFT JOIN,RIGHT JOIN,INNER JOIN or FULL OUTER JOIN instead of only OUTER JOIN.

There is also one error with your table name there shouldn't be space between the letters of a table like this [company C- it should be named as company_C]

I hope that will be work..All the best!



来源:https://stackoverflow.com/questions/12473210/mysql-outer-join-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!