值表
id name attributes_id
1 black 3 [->]
2 red 3 [->]
3 blue 3 [->]
5 tortorise 3 [->]
6 oakley 1 [->]
9 green 3 [->]
10 native 1 [->]
product_values表
values_id products_id
1 [->] 5 [->]
2 [->] 10 [->]
SQL
SELECT values.name, product_values.products_id FROM `product_values` inner
join values ON product_values.values_id=values.id;
错误
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 'values on
product_values.values_id=values.id' at line 1
感谢您的帮助。
答案 0 :(得分:3)
您应该在values
表引用周围添加一些引号。这是一个reserved word
SELECT
`values`.name,
product_values.products_id
FROM
product_values
INNER JOIN `values` ON product_values.values_id = `values`.id;
答案 1 :(得分:0)
根据手册,VALUES
是mysql的保留关键字。见这里:MySQL Reserved Keywords List。为了避免语法错误,应使用名为backtick的符号转义关键字或列名称。例如,
SELECT values.name, product_values.products_id
FROM `product_values`
inner join `values` ON product_values.values_id = `values`.id;