user1045373
user1045373

Reputation: 193

How can i use conditional operators with like in my sql query?

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

Answers (3)

renick
renick

Reputation: 3881

SELECT count(*) 
FROM  `table` 
WHERE FIND_IN_SET( col_name,  '56,80,95' ); 

Upvotes: 0

sverdianto
sverdianto

Reputation: 134

SELECT COUNT(ID) FROM TABLE_NAME WHERE COL_NAME LIKE "%56%" OR COL_NAME LIKE '%80%'

Maybe?

Upvotes: 0

Hemant Metalia
Hemant Metalia

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

Related Questions