为什么此查询会引发错误(#1064 - 您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,了解在 'of France' AND Countries 附近使用的正确语法。name = 'France' ) AND(第 1 行的 Landmarks .top_c'):
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 )
和完全相同的代码,但格式化,不会抛出错误:
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
)
?
在MySQL 中,字符串数据类型被单个撇号 - 包围
'some text'
,这就是您收到错误的原因。