Jump to content

Recommended Posts

I am trying to create a select statement and keep running into problems

 

I have a table with columns

id int

client text

category text

 

Category contains a list of ids so examples are

 

1,3,12,16,20

12,25,17,122

23,122

12

 

I am trying to count the number of rows that contain a number in the category ie contain 12 and I expect to get 3 rows but can't get it to work

 

select count(*)

from clients

where category in ('12')

 

only returns 1 but

 

where category like '%12%' returns 4

 

I'm stuck, please help.

 

Link to comment
https://forums.phpfreaks.com/topic/2834-select-problem/
Share on other sites

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']select[/span] count(*) from `clients` where `category` like '%,12,%' or `category` like '12,%' or `category` like '%,12' [!--sql2--][/div][!--sql3--]

Link to comment
https://forums.phpfreaks.com/topic/2834-select-problem/#findComment-9500
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.