I have two tables product and category table. On my website, I want to filter my product based on categories. So I am passing the categories ids as a query string in the URL. The ID's are passed in the URL as comma separated string.
I need a MySQL query or stored procedure that can search in the product table based on the category ids.
Product Table | ID | Product_name | Categories | | 1 | TV 1 | LED, 32 inch, HD | | 2 | TV 2 | OLED, 55 inch, Ultra HD (4K) | | 3 | TV 3 | LCD , 24 inch, HD | | 4 | TV 4 | LED, 55 inch, Full HD | Category Table | ID | Category Name | | 1 | LED | | 2 | OLED | | 3 | LCD | | 4 | 32 inch | | 5 | 55 inch | | 6 | 24 inch | | 7 | HD | | 8 | Full HD | | 9 | Ultra HD (4K) |
If the filter query string is "1,3,7" the Product table should return below output
Product Table | ID | Product_name | Categories | | 1 | TV 1 | LED, 32 inch, HD | | 3 | TV 3 | LCD , 24 inch, HD |
What query or stored procedure should be in MySQL?