![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Say I wanted to create a query to select all the users whose emails belong to two or more users. How would I go about doing this? Here's what I have, so far (and which hasn't worked): SELECT * FROM users WHERE email IN (SELECT email FROM users GROUP BY email HAVING count(*) > 1)) Any ideas? |
#3
| |||
| |||
|
|
Say I wanted to create a query to select all the users whose emails belong to two or more users. How would I go about doing this? |
#4
| |||
| |||
|
|
yawnmoth wrote: Say I wanted to create a query to select all the users whose emails belong to two or more users. How would I go about doing this? Here's what I have, so far (and which hasn't worked): SELECT * FROM users WHERE email IN (SELECT email FROM users GROUP BY email HAVING count(*) > 1)) Any ideas? untested SELECT t1.id, t1.username FROM ( SELECT DISTINCT email, count( email ) FROM users GROUP BY email HAVING count( email ) >1 )t2 LEFT JOIN users t1 ON t1.email = t2.email Thanks! |
![]() |
| Thread Tools | |
| Display Modes | |
| |