Jump to content

help sql noober please!!


vitid

Recommended Posts

let say that i have 3 tables as follow

 

member

id

name

1

a

2

b

3

c

 

group

id

name

1

group1

2

group2

 

groupmembermap

group_idmember_id

11

12

21

23

 

how to create statement to return group's name that has both member name a and b please help me , i try googling for an hour with no success , i try subquery  it but guess i'm hopeless , thank you.

 

Link to comment
https://forums.phpfreaks.com/topic/147297-help-sql-noober-please/
Share on other sites

how about this?

select g.name
from group as g
cross join member as m1
cross join member as m2
inner join groupmembermap as gm1 on ( gm1.group_id = g.id and gm1.member_id = m1.id )
inner join groupmembermap as gm2 on ( gm1.group_id = g.id and gm1.member_id = m1.id )
where m1.name = 'a' and m2.name = 'b'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.