SELECT add.id_address,
add.alias,
add.firstname,
add.lastname,
add.postcode,
add.city,
add.address1,
add.address2,
cl.name as country
FROM address add,
country_lang cl
WHERE add.id_customer=2 AND cl.id_lang=3
AND add.id_country=cl.id_country AND add.active=1
ORDER BY add.id_address ASC
答案 0 :(得分:5)
请勿使用add
作为表别名。这是一个保留的关键字。
答案 1 :(得分:1)
add
是reserved keyword您必须将其转义或使用其他别名,例如FROM address a
而不是FROM address add
,如下所示:
SELECT a.id_address, a.alias, a.firstname,
a.lastname, a.postcode, a.city,
a.address1, a.address2, cl.name as country
FROM address a, country_lang cl
WHERE a.id_customer = 2 AND cl.id_lang=3
AND a.id_country = cl.id_country
AND a.active=1
ORDER BY a.id_address ASC
答案 2 :(得分:1)
如果您想以下列方式使用backtick
,则必须使用reserved keyword
:
SELECT `add`.id_address, `add`.alias, `add`.firstname,
`add`.lastname, `add`.postcode, `add`.city,
`add`.address1, `add`.address2, cl.name as country
FROM address `add`, country_lang cl
WHERE `add`.id_customer = 2 AND cl.id_lang=3
AND `add`.id_country = cl.id_country
AND `add`.active=1
ORDER BY `add`.id_address ASC
除了例外,我建议您按以下方式使用JOIN:
SELECT a.id_address,
a.alias,
a.firstname,
a.lastname,
a.postcode,
a.city,
a.address1,
a.address2,
cl.name as country
FROM address a JOIN country_lang cl ON a.id_country=cl.id_country
WHERE a.id_customer=2 AND cl.id_lang=3 AND a.active=1
ORDER BY a.id_address ASC