What alternative methods can be used to group email domains besides substring_index in MySQL?

When grouping email domains in MySQL, an alternative method to substring_index is to use the SUBSTRING_INDEX function combined with the RIGHT function. This allows for extracting the domain portion of an email address without relying on a fixed delimiter like substring_index does. By using SUBSTRING_INDEX to separate the domain from the email address and RIGHT to extract the domain portion, you can effectively group email domains in MySQL.

SELECT SUBSTRING_INDEX(email, '@', -1) AS domain,
COUNT(*) AS count
FROM users
GROUP BY RIGHT(SUBSTRING_INDEX(email, '@', -1), LENGTH(SUBSTRING_INDEX(email, '@', -1)) - INSTR(SUBSTRING_INDEX(email, '@', -1), '.'))
ORDER BY count DESC;