开发者

What kind of SQL join would this be?

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

exp_member_groups
-group_id
-grou开发者_开发技巧p_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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜