Select rows with same email

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Terriator
Forum Commoner
Posts: 60
Joined: Mon Jul 04, 2005 12:46 pm

Select rows with same email

Post by Terriator »

Hey, I'm looking for a query, with which I would be able to select all rows in a usertable, that have a email that's present 2 or more times in the same usertable. How would I do that?
Terriator
Forum Commoner
Posts: 60
Joined: Mon Jul 04, 2005 12:46 pm

Post by Terriator »

Mysql should I probably remember to say >_>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You group by email, and restrict those groups that exist out of at least 2 items...

Code: Select all

SELECT email, COUNT(*) FROM table GROUP BY email HAVING COUNT(*) >= 2;
Post Reply