sql - Get all rows with a matching field in a different row in the same table -
let's have table this:
|id|userid|email |website | -------------------------------------- |1 |user1 |user1@test.com|website.com| |2 |user2 |user2@test.com|website.com| |3 |user3 |user3@test.com|website.com| |4 |user1 |user1@test.com|foo.com | |5 |user2 |user2@test.com|foo.com |
and want of rows website='website.com' , have corresponding row matching userid website='foo.com'
so, in instance return rows 1 , 2.
any ideas?
to user can do
select userid your_table website in ('website.com', 'foo.com') group userid having count(distinct website) = 2
but if need complete row do
select * your_table userid in ( select userid your_table website in ('website.com', 'foo.com') group userid having count(distinct website) = 2 )
Comments
Post a Comment