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

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -