0
votes

I have two Table call category table and product table
and single product can have multiple categories for eg: 1,2,3, in category page like to show all products related to categoryid

I wrote queries E.g (select * from producttable where categoryid = 1), how would i match particular categoryid with ProductTable categoryid column ?

following are my table information

Category Table
id | categoryname 
1  | abc
2  | pqr
3  | xyz

product Table 
id | productname | categoryid
1  | abc         | 1,2,3  
1
You wouldn't. See normalization - Strawberry
Internet search : 'mysql search comma separated value' returns useful links. However, please do as @Strawberry suggests, and restructure your tables, it will be a lot easier later. - Ryan Vincent

1 Answers

0
votes

use like operator

SELECT * FROM product where categoryid LIKE '%1%';

or you can use regular expression in your sql.