lisbeth lisbeth - 5 months ago 15
MySQL Question

1064 - You have an error in your SQL syntax (...) near ''

Running this sql query in mysql:

INSERT INTO Test_id_isbnyear
SELECT I.id, I.isbn, Y.year
FROM Prod_id_isbn AS I
LEFT JOIN Prod_id_year AS Y ;


Throw this error:


1064 - You have an error in your SQL syntax (...) near '' at line 4




How can I get an error about a '"' if there is no such thing in my query?

Answer

Admittedly the error message isn't super helpful in this case. There may be exceptions to the rule, but in my experience this usually means that the syntax error is at the very end of the query. Which, in this case, it is:

SELECT I.id, I.isbn, Y.year    
FROM Prod_id_isbn AS I     
LEFT JOIN Prod_id_year AS Y
-- missing "ON" clause

Should be something like:

SELECT I.id, I.isbn, Y.year    
FROM Prod_id_isbn AS I     
LEFT JOIN Prod_id_year AS Y
  ON I.SomeField = Y.SomeField