mySql 查询给我语法错误

mySql query give me syntax error

在 phpMyAdmin 中给我这个错误:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table ON brand.seo_name = table.brandName ORDER BY b' at line 8

这是查询:

SELECT brand.name, brand.seo_name
FROM brand
JOIN (
    SELECT IFNULL(product.brand, standard_product.brand) AS brandName
    FROM product
    JOIN standard_product
    ON product.standard_product_id = standard_product.id
    WHERE product.store_id = 1) AS table
ON brand.seo_name = table.brandName

ORDER BY brand.seo_name ASC
LIMIT 0,30

table 是保留字。您应该选择不同的别名,例如 t:

SELECT brand.name, brand.seo_name
FROM brand
JOIN (
    SELECT IFNULL(product.brand, standard_product.brand) AS brandName
    FROM product
    JOIN standard_product
    ON product.standard_product_id = standard_product.id
    WHERE product.store_id = 1) t
ON brand.seo_name = t.brandName
ORDER BY brand.seo_name ASC
LIMIT 0,30

您不能将 'table' 用于 AS。 'table' 是保留字。使用不同的东西,例如 'temptable'.