I have a MySQL table with values like:
+--------------+
| user_email |
+--------------+
| ab@gmail.com |
| cd@gmail.com |
| ef@yahoo.com |
| gh@yahoo.com |
| ij@gmail.com |
| kl@other.net |
+--------------+
I need to return a list of unique domain names from this list of email address, such as:
gmail.com, yahoo.com, other.net
So far, I am using the following SQL statement to select this:
SELECT SUBSTRING_INDEX(user_email,'@',-1)
However, this only solves half of my problem - it is returning domain names. Using DISTINCT did not do the trick. What am I missing?
FYI: This is running on a LAMP stack. Thanks!