Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown column in 'on clause' with FULL JOIN MySQL keyword

Tags:

mysql

I have a problem with FULL JOIN keyword used in MySQL

SELECT Name,Surname,Notes.Payment FROM Persons FULL JOIN Notes ON  Persons.id=Notes.P_Id

it give me this error :

Unknown column 'Persons.id' in 'on clause'

but if I call with LEFT JOIN or RIGHT JOIN, the results appear properly.

What is the problem with FULL JOIN ?

Thank you

like image 900
Teodorescu Avatar asked Sep 07 '11 14:09

Teodorescu


1 Answers

MySQL does not (yet) support FULL JOIN.

Use something like this:

  SELECT Name, Surname, Notes.Payment 
  FROM Persons 
    LEFT JOIN Notes 
      ON Persons.id = Notes.P_Id
UNION ALL
  SELECT Name, Surname, Notes.Payment 
  FROM Persons 
    RIGHT JOIN Notes 
      ON Persons.id = Notes.P_Id
  WHERE Persons.id IS NULL

The error you get is because FROM Persons FULL JOIN Notes ON is parsed as:

FROM Persons AS FULL 
  JOIN Notes
    ON ...
like image 99
ypercubeᵀᴹ Avatar answered Oct 14 '22 00:10

ypercubeᵀᴹ