I have a problem in getting records in 1 to many relationship. following is the scenario,
table products
---------------------
id | name
---------------------
1 | product1
2 | product2
3 | product3
4 | product4
Categories
-------------
id | name
-------------
1 | A
2 | B
3 | C
product_categories
-------------------
pid | cid
-------------------
1 | 1
1 | 2
1 | 3
2 | 2
2 | 3
3 | 2
3 | 3
4 | 3
I want to select products based on category name.
if my condition is category B and C then the expected output would be,
Expected Result:
----------------------------
Product_name | category_name
----------------------------
Product2 | B
Product2 | c
Product3 | B
Product3 | c
if my category is C then only product4 should be shown.
Please help me in this.. I have tried so many ways and techniques like IN, NOT IN, exists and not exists along with possible join operations but nothing worked.