如何在此查询中进行正确的内连接?

时间:2017-07-08 13:29:16

标签: mysql sql

SELECT p.product_id, p.quantity, p.price, pd.name, pd.description
FROM product AS p
INNER JOIN product_description AS pd ON p.product_id = pd.product_id
WHERE p.product_id = 1 AND pd.landuage_id = 5

在此查询中,只存在一个条件,在这种情况下为p.product_id,但另一个条件pd.landuage_id不存在。我希望执行请求,无论它是否存在。怎么做?

1 个答案:

答案 0 :(得分:1)

可能重复,但正确答案是:

SELECT p.product_id, p.quantity, p.price, pd.name, pd.description
FROM product p 
LEFT JOIN product_description pd ON p.product_id = pd.product_id AND pd.language_id = 5
WHERE p.product_id = 1;