Why this query generates an error ( # syntax; syntax; syntax; syntax; syntax; Landmarks. Top_c 'at line 1):

SELECT * FROM Landmarks INNER JOIN Localities ON Landmarks.locality_id = Localities.locality_id INNER JOIN Regions ON Localities.region_id = Regions.region_id INNER JOIN Countries ON Regions.country_id = Countries.country_id WHERE ( Localities.name = 'Normandy' AND Regions.name = 'North of France' AND Countries.name = 'France' ) AND ( Landmarks.top_choice = 1 OR Landmarks.history = 1 OR Landmarks.military = 1 ) AND ( Landmarks.car = 1 ) 

but the exact same code, but formatted, does not give an error:

  SELECT * FROM Landmarks INNER JOIN Localities ON Landmarks.locality_id = Localities.locality_id INNER JOIN Regions ON Localities.region_id = Regions.region_id INNER JOIN Countries ON Regions.country_id = Countries.country_id WHERE ( Localities.name = 'Normandy' AND Regions.name = 'North of France' AND Countries.name = 'France' ) AND ( Landmarks.top_choice = 1 OR Landmarks.history = 1 OR Landmarks.military = 1 ) AND ( Landmarks.car = 1 ) 

?

  • I think it's in the "wrong" quotes ... - MaxU

1 answer 1

In MySQL, the string data type is framed in a single apostrophe - 'some text' , that's why you get an error.