0

我有三张桌子:

USER
用户
名 fname
lname

GROUP
groupid
说明

USER_GROUP
usergroupid
userid
groupid

我需要获取用户表的名字和姓氏。给出的是组描述。我怎样才能做到这一点?

4

3 回答 3

1

尝试这个:

SELECT USER.*
FROM USER 
  INNER JOIN USER_GROUP ON USER.userid = USER_GROUP.userid
  INNER JOIN [GROUP] ON USER_[GROUP].groupid = [GROUP].groupid
WHERE [GROUP].description = 'Blah blah'
于 2013-03-20T13:58:37.120 回答
1

怎么样

   Select FName, LName
   From user u
   Where Exists 
       (Select * From user_Group ug
            join group g On g.GroupId = ug.groupId
        Where ug.userId = u.UserId
            anf g.description = @GroupDescription)  
于 2013-03-20T13:59:50.273 回答
1
SELECT  a.Fname,
        a.LName,
        c.Description
FROM    [USER] a
        INNER JOIN [USER_GROUP] b
            ON a.userID = b.userID
        INNER JOIN [GROUP] c
            ON b.groupid = c.groupID
WHERE   c.Description = 'description_here'

要进一步了解有关联接的更多信息,请访问以下链接:

于 2013-03-20T13:55:10.110 回答