一尘不染

SQL多对多选择

sql

category_product
---------------
id_category
id_product

product
---------------
id_product
id_manufacturer

manufacturer
---------------
id_manufacturer
name

我将如何创建一个SQL查询,以便当id_category等于某个值时从制造商中选择所有名称?


阅读 226

收藏
2021-03-17

共1个答案

一尘不染

这是表的直接内部连接:

SELECT m.name, cp.id_category
FROM manufacturer as m
INNER JOIN product as p
    ON m.id_manufacturer = p.id_manufacturer
INNER JOIN category_product as cp
    ON p.id_product = cp.id_product
WHERE cp.id_category = 'some value'
2021-03-17