Reputation: 20346
Suppose I have a table like this:
id name email_account
1 Matt hotmail
2 Matt yahoo
3 Luis hotmail
4 Rita gmail
5 Samy hotmail
6 Rita yahoo
As you can see from this table, Matt has both a hotmail and a yahoo account. Rita also has 2 email accounts (gmail and yahoo). How do I (with SQL in MySQL) get all the people in this table that has at least 2 different email accounts (like Matt and Rita)
Upvotes: 2
Views: 158
Reputation: 848
if (mysql_num_rows($query) > 1)
...?
I wouldn't recommend this though. Instead, create another column.
Or in MySQL:
SELECT name, COUNT(name) FROM orders
GROUP BY table
HAVING COUNT(name) > 1
This will select people with duplicate names, which means, same people with different email accounts.
Upvotes: 0
Reputation: 7336
Something like this should work:
SELECT name
FROM my_table
GROUP BY name HAVING count(email_account) > 1
Upvotes: 3
Reputation: 12940
SELECT name
FROM Table
GROUP BY name
HAVING COUNT(email_account) > 1
Upvotes: 9