Count Email Address Domains

Like this blog? Consider exploring one of our sponsored banner ads...

A quick tidbit I came up with today to count email addresses in a mysql database table grouping them by domain. So say for example you have a large list of subscribers and you want to see the breakdown of people who use Hotmail, Yahoo, Gmail, etc.

SELECT COUNT( SUBSTRING_INDEX( `email` , '@', -1 ) ) AS `count` , 
SUBSTRING_INDEX( `email` , '@', -1 ) AS `domain`
FROM `subscribers` WHERE `email` != '' 
GROUP BY `domain`

This sql statement assumes that the table is called ‘subscribers’ and the column containing the email addresses is ‘email’. Change these two values to match your table name and email address column name.

About this entry