TheMilkCarton
06-25-2007, 04:28 PM
Hi, I have this:
SELECT email,username,
COUNT(email) AS NumOccurrences
FROM user
GROUP BY email
HAVING ( COUNT(email) > 1 )
And it works just fine, but I was wondering how to make it so that it actually LISTS each occurence?
For example, it gives me this
username_____email_________ numOccurrences
user1 -------- blah@blah.com -----3
otheruser1 ---- ***@***.com -----4
but I would like it to give me this:
username_____email_________ numOccurrences
user1 -------- blah@blah.com -----3
user2 -------- blah@blah.com -----3
user3 -------- blah@blah.com -----3
otheruser1 ---- ***@***.com -----4
otheruser2 ---- ***@***.com -----4
otheruser3 ---- ***@***.com -----4
otheruser4 ---- ***@***.com -----4
This of course becomes redundant, and the "numOccurrences" column would be kind of unnecessary, but I'm really stupid with MySQL and can't seem to figure this out.
Thanks!
SELECT email,username,
COUNT(email) AS NumOccurrences
FROM user
GROUP BY email
HAVING ( COUNT(email) > 1 )
And it works just fine, but I was wondering how to make it so that it actually LISTS each occurence?
For example, it gives me this
username_____email_________ numOccurrences
user1 -------- blah@blah.com -----3
otheruser1 ---- ***@***.com -----4
but I would like it to give me this:
username_____email_________ numOccurrences
user1 -------- blah@blah.com -----3
user2 -------- blah@blah.com -----3
user3 -------- blah@blah.com -----3
otheruser1 ---- ***@***.com -----4
otheruser2 ---- ***@***.com -----4
otheruser3 ---- ***@***.com -----4
otheruser4 ---- ***@***.com -----4
This of course becomes redundant, and the "numOccurrences" column would be kind of unnecessary, but I'm really stupid with MySQL and can't seem to figure this out.
Thanks!