I have data like below. If i search Product "P1" then
I need all the category which has the product "P1"
I need all the products that are related to the category from step 1
Explanation: Product P1 avail in Categories in C1,C2,C4. So, I'll consider all the products from these categories and category C2 contains two products which are P1,P4.
So, I have to consider category C3 as well because product P4 avail in C3. Similar way to check for all the records and get data.
I can achieve this using Cursor, for loops in stored procedure and temp tables. Is there any way to get data by using query?
A Simple SQL query like below should do the job,
Output :