views:

70

answers:

3

I need to go to two tables to get the appropriate info

exp_member_groups
-group_id
-group_title

exp_members
-member_id
-group_id

I have the appropriate member_id

So I need to check the members table, get the group_id, then go to the groups table and match up the group_id and get the group_title from that.

+4  A: 

INNER JOIN:

SELECT exp_member_groups.group_title
FROM exp_members
INNER JOIN exp_member_groups ON exp_members.group_id = exp_member_groups.group_id
WHERE exp_members.member_id = @memberId
Michael Bray
+2  A: 
SELECT g.group_title
FROM exp_members m
    JOIN exp_member_groups g ON m.group_id = g.group_id
WHERE m.member_id = @YourMemberId
AdaTheDev
+1  A: 

If there is always a matching group, or you only want rows where it is, then it would be an INNER JOIN:

SELECT  g.group_title
FROM    exp_members m
        INNER JOIN
                exp_member_groups g
                ON m.group_id = g.group_id
WHERE   m.member_id = @member_id

If you want rows even where group_id doesn't match, then it is a LEFT JOIN - replace INNER JOIN with LEFT JOIN in the above.

David M