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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -