views:

98

answers:

3

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?

A: 

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
Tim
A: 

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.

akiller
Justin Johnson
thats still not the full one, the full one is 6300+ characters long
fuzzy lollipop
This is perfect, I didn't really think of regex. Thanks!
jwzk
+1  A: 

If you want the number of them you'd do

SELECT COUNT(DISTINCT('EMAIL')) FROM 'TABLE'
silent1mezzo
I do actually need to know if they're valid in this case.
jwzk
you can use a regexp as suggested below...
t00ny