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
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'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.