SELECT substring_index(email, '@', -1), COUNT(*) as counter FROM table WHERE email IS NOT NULL and email != '' GROUP BY substring_index(email, '@', -1) ORDER BY counter DESC;