+ 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?

8th May 2017, 7:09 PM
Joas Dioniz
Joas Dioniz - avatar
2 Answers
+ 1
SELECT * FROM shops_products JOIN products ON (shops_products.product_id = products.id) WHERE shops_products.shop_id = 1
8th May 2017, 7:41 PM
Jeth
Jeth - avatar
+ 1
SELECT * FROM Products WHERE Product_ID IN ( SELECT Product_ID FROM SHOPS_PRODUTS WHERE Shop_ID = 1 )
16th May 2017, 6:33 PM
Thulasi Makkena
Thulasi Makkena - avatar