tags:

views:

28

answers:

2

how i can write the query ex;-

select count(id) where animal = rat , elephant ,cat, mouse

how i can do this in mysql. ex means count the row where animal = rat ,elephant, cat ,mouse

+4  A: 

This is almost correct. You write

WHERE var IN (value1, value2, ..., valueN)

This is equivalent with

WHERE var = value1 OR var = value2 OR var = .... OR var = valueN
Ingo
+4  A: 

This will return a single COUNT for all matching animals:

SELECT  COUNT(id)
WHERE   animal IN ('rat', 'elephant' , 'cat', 'mouse')

This will count animal-wise:

SELECT  animal, COUNT(id)
WHERE   animal IN ('rat', 'elephant' , 'cat', 'mouse')
GROUP BY
        animal

i. e. will return how many rats, elephants etc. are there in the table.

Quassnoi