Reputation: 83
I want to get the total number of all valid e-mail address in a database, but I also want the total to be unique e-mail addresses. Is this possible with mysql alone?
Upvotes: 0
Views: 3115
Reputation: 2942
If you want the number of them you'd do
SELECT COUNT(DISTINCT('EMAIL')) FROM 'TABLE'
Upvotes: 1
Reputation: 2472
Something like this maybe?
SELECT `email`
FROM `users`
WHERE `email`
REGEXP '[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'
GROUP BY `email`
Regex was from here. As the site points out, this may not match all valid emails (i.e. the obscure ones). The last time I looked into it I'm not sure if anyone had created a regular expression which would match every possible email address.
Upvotes: 3
Reputation: 9489
You can't check if an e-mail is valid with mysql.
You can select all unique e-mail with a distinct select:
SELECT DISTINCT `e-mailadress`FROM `table1` //something like this
Upvotes: 1