Reputation: 193
I want to count number between say 56,80,95 and 108 from a column of my table where i have stored digits seperated with a ",". Now, I want to count the primary id's of the columns which contains any of the above number using like or some other way. I tried using like as below:
SELECT COUNT(DISTINCT(ID)) FROM TABLE_NAME WHERE COL_NAME LIKE "%56%" OR '%80%'
SELECT COUNT(DISTINCT(ID)) FROM TABLE_NAME WHERE COL_NAME LIKE ("%56%" OR '%80%')
NON OF THIS WORKS
Upvotes: 0
Views: 133
Reputation: 3881
SELECT count(*)
FROM `table`
WHERE FIND_IN_SET( col_name, '56,80,95' );
Upvotes: 0
Reputation: 134
SELECT COUNT(ID) FROM TABLE_NAME WHERE COL_NAME LIKE "%56%" OR COL_NAME LIKE '%80%'
Maybe?
Upvotes: 0
Reputation: 30648
you can do
SELECT COUNT(DISTINCT(ID)) FROM TABLE_NAME WHERE COL_NAME LIKE "%56%" OR COL_NAME LIKE '%80%'
refer example queries
Upvotes: 3