tags:

views:

40

answers:

3

Can I get the count results for particular field from table. for example im using this query,

select id,retailer,email from tab

i got the result set,

   1  ret1 [email protected]
   2  ret2 [email protected]
   3  ret3 [email protected]
   4  ret1 [email protected]
   5  ret2 [email protected]
   6  ret6 [email protected]

What I need is count of ([email protected]) as 3 times like wise. thanks.

A: 

To count a single email:

select count(id)
from tab
where email = '[email protected]'

or to count all email values:

select email, count(email)
from tab
group by email
Andy White
+1  A: 

This will give you the count of all email addresses in that table:

SELECT email, COUNT(*) FROM tab GROUP BY email;

If you want to get only one particular one count use this:

SELECT COUNT(*) FROM tab WHERE email = '[email protected]';
RaYell
thanks. it works.
paulrajj
A: 

To group all of your emails together to count them:

  SELECT email
       , COUNT(*) AS 'count'
    FROM `tab`
GROUP BY email

If you're looking for just a single email address:

  SELECT email
       , COUNT(*) AS 'count'
    FROM `tab`
   WHERE email = '[email protected]'
AvatarKava
i have already changed and got the results as like your answer. thanks.
paulrajj