0

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

3
  • Can you elaborate your question? and from your query I am guessing you have stored the column name with numbers? Commented Jan 3, 2012 at 10:46
  • 2
    NON OF THIS WORKS --- BREAKING NEWS!!! Commented Jan 3, 2012 at 10:46
  • Don't guess, just run select "%56%" OR '%80%'. You'll see it's zero (boolean false). The LIKE operator expects a string, not a boolean. Commented Jan 3, 2012 at 11:02

3 Answers 3

3

you can do

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

refer example queries

Sign up to request clarification or add additional context in comments.

1 Comment

an d what if have have lot of digits to compare say 50 different digit to compare?? den should i write all the digits as above??
0
SELECT COUNT(ID) FROM TABLE_NAME WHERE COL_NAME LIKE "%56%" OR COL_NAME LIKE '%80%'

Maybe?

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.