mySql查询给我语法错误

时间:2017-01-05 15:06:09

标签: mysql sql phpmyadmin subquery syntax-error

在phpMyAdmin中给我这个错误:

  

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以获得在&table;表附近使用的正确语法               ON brand.seo_name = table.brandName   订购b'在第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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

您无法使用表格'对于AS。 '表'是一个保留字。使用不同的东西,比如' temptable'。

相关问题