对你们来说可能是一个facepalm,但作为一个SQL查询新手,我遇到了语法问题。谁知道什么是错的?
SELECT * FROM company C
OUTER JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL
给出错误:
#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
答案 0 :(得分:53)
In MySQL你应该使用LEFT OUTER JOIN或RIGHT OUTER JOIN。没有只是外部加入。如果您需要MySql you can use UNION of LEFT JOIN and RIGHT JOIN
中的FULL OUTER JOIN答案 1 :(得分:6)
尝试
SELECT * FROM company C
LEFT JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL
答案 2 :(得分:1)
您必须编写LEFT JOIN,RIGHT JOIN,INNER JOIN或FULL OUTER JOIN,而不仅仅是 OUTER JOIN 。
您的表格名称也有一个错误,像[ company C ”这样的表格的字母之间不应有空格-应该将其命名为< strong> company_C ]
我希望那会工作。。祝一切顺利!