Paulraj
Paulraj

Reputation: 3397

Counting the particular field from table

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.

Upvotes: 0

Views: 97

Answers (3)

AvatarKava
AvatarKava

Reputation: 15443

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]'

Upvotes: 0

RaYell
RaYell

Reputation: 70414

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]';

Upvotes: 2

Andy White
Andy White

Reputation: 88355

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

Upvotes: 0

Related Questions