调整SQL查询

时间:2011-07-25 06:26:37

标签: mysql sql

我有以下查询:

  SELECT product_description.name, product.quantity,product.price
    FROM product
    INNER JOIN product_description
    ON product.product_id=product_description.product_id
    ORDER BY product_description.name 

我需要加入更多的表格,我已尝试过以下内容,但我不确定如何将我的ON扩展到一对以上。

错误:(在线)

SELECT product_description.name, product.quantity,product.price,product_option_value_description.name
FROM product
INNER JOIN product_description, product_option_value_description
ON product.product_id=product_description.product_id=product_option_value_description.product_id
ORDER BY product_description.name

2 个答案:

答案 0 :(得分:4)

您必须为要加入的每个表使用单独的联接

...
JOIN Table1 ON ...
JOIN Table2 ON ...
...

答案 1 :(得分:2)

SELECT pd.name,p.quantity,p.price,povd.name
FROM product p
INNER JOIN product_description pd ON p.product_id=pd.product_id
INNER JOIN product_option_value_description povd ON p.product_id=povd.product_id
ORDER BY pd.name