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
user1711597
问问题
166 次
3 回答
5
不要add
用作表别名。它是一个保留关键字。
于 2012-10-01T11:22:02.503 回答
1
add
是一个保留关键字,您必须对其进行转义或使用其他别名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
于 2012-10-01T11:22:49.563 回答
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
于 2012-10-01T11:23:44.013 回答