jwzk
jwzk

Reputation: 83

Mysql - Valid Unique E-mail

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

Answers (3)

silent1mezzo
silent1mezzo

Reputation: 2942

If you want the number of them you'd do

SELECT COUNT(DISTINCT('EMAIL')) FROM 'TABLE'

Upvotes: 1

akiller
akiller

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

Tim
Tim

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

Related Questions