0

give me this error in 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

this is the query:

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
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Matteo Villa
  • 47
  • 2
  • 12

2 Answers2

1

table is a reserved word. You should choose a different alias, such as 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
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

You can't use 'table' for the AS. 'table' is a reserved word. Use something different like 'temptable'.