Quote:
|
Originally Posted by certus
Select username
from usertable a, likestable b, userlikestable c
where a.userid=c.userid
and b.likesid=c.likesid
and (b.likestype = fishing
or b.likestype = cycling)
|
That finds people who like fishing OR cycling. For fishing AND cycling you could do this:
Code:
Select username
from usertable a, likestable b1, userlikestable c1, likestable b2, userlikestable c2
where a.userid=c1.userid
and b1.likesid=c1.likesid
and b1.likestype = 'fishing'
and a.userid=c2.userid
and b2.likesid=c2.likesid
and b2.likestype = 'cycling'
Or:
Code:
Select a.username
from usertable a
where a.userid IN
(select c.userid
from likestable b, userlikestable c
where b.likesid=c.likesid
and b.likestype = 'fishing'
INTERSECT
select c.userid
from likestable b, userlikestable c
where b.likesid=c.likesid
and b.likestype = 'cycling'
)