Copy link to clipboard
Copied
Id Name Category ( comma separated checkbox vlues in category )
001 abc 1,2
002 xyz 2,3
003 zzz 0,1
QUESTION:
I want to get recoreds of those category which have category 1 and 0 ..
Select *
FROM Table
Where ?
Thank,
Should normalize to have a mapping table instead:
Map
==========
Id Category
001 1
001 2
002 2
002 3
003 0
003 1
Then you use a JOIN to get the matching records:
SELECT Table.*
FROM Table INNER JOIN
Map ON Table.Id = Map.Id
WHERE Map.Category IN ( 0, 1 )
To do it with your current data model, you have to do something like this:
SELECT *
FROM Table
WHERE ',' + Category + ',' LIKE '%,0,%'
OR ',' + Category + ',' LIKE '%,1,%'
Copy link to clipboard
Copied
Should normalize to have a mapping table instead:
Map
==========
Id Category
001 1
001 2
002 2
002 3
003 0
003 1
Then you use a JOIN to get the matching records:
SELECT Table.*
FROM Table INNER JOIN
Map ON Table.Id = Map.Id
WHERE Map.Category IN ( 0, 1 )
To do it with your current data model, you have to do something like this:
SELECT *
FROM Table
WHERE ',' + Category + ',' LIKE '%,0,%'
OR ',' + Category + ',' LIKE '%,1,%'