27

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
Pang
  • 9,564
  • 146
  • 81
  • 122
Sem
  • 4,477
  • 4
  • 33
  • 52

3 Answers3

61

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

lewis
  • 2,936
  • 2
  • 37
  • 72
valex
  • 23,966
  • 7
  • 43
  • 60
  • 1
    @philipxy fair enough, I just found it hard to parse ("to clarify the meaning of a post without changing it"), but I didn't consider that could be just me. Good feedback, thank you. – lewis Feb 26 '22 at 15:30
  • @lewis Unfortunately a lot of site protocols/conventions/policies are poorly documented. (Also there is not always consensus.) For site use Q&A google [meta] & [meta.se] via 'site:'. – philipxy Feb 26 '22 at 22:12
8

Try

SELECT * FROM company C
LEFT JOIN company_address A ON C.company_id = A.company_id
WHERE A.company_id IS NULL
podiluska
  • 50,950
  • 7
  • 98
  • 104
1

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!

Anmol
  • 11
  • 1