• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

QUERY : comma separated checkbox vlues in category

New Here ,
Dec 04, 2010 Dec 04, 2010

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,

Views

366

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Dec 04, 2010 Dec 04, 2010

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,%'

Votes

Translate

Translate
Contributor ,
Dec 04, 2010 Dec 04, 2010

Copy link to clipboard

Copied

LATEST

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,%'

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation