+ 1
Many to many relationship in SQL
I have two tables, one called shops and another called products both are joined with table called shops_products. Here I want to select all products with a given shop id from shops. how could I write a SQL?
2 Respostas
+ 1
SELECT * FROM shops_products JOIN products ON (shops_products.product_id = products.id) WHERE shops_products.shop_id = 1
+ 1
SELECT * FROM Products
WHERE Product_ID IN (
SELECT Product_ID
FROM SHOPS_PRODUTS
WHERE Shop_ID = 1
)