Tsql m:n关系中的select语句
我有三张桌子: 用户Tsql m:n关系中的select语句,tsql,select,many-to-many,Tsql,Select,Many To Many,我有三张桌子: 用户 用户ID fname lname 组 groupid 说明 用户组 usergroupid 用户ID groupid 我需要得到users表的名字和姓氏。给出的是组描述。我怎样才能做到这一点 SELECT a.Fname, a.LName, c.Description FROM [USER] a INNER JOIN [USER_GROUP] b ON a.userID = b.userID
用户ID
fname
lname
组
groupid
说明
用户组
usergroupid
用户ID
groupid
我需要得到users表的名字和姓氏。给出的是组描述。我怎样才能做到这一点
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'
要进一步了解加入的更多信息,请访问以下链接:
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'
试试这个:
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'
怎么样
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)
怎么样
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)
好的,我已经测试过了,它似乎是有效的,现在我唯一的问题是,也许我也应该提到这一点,如何从另一个gridview传递@GroupDescription变量?我使用2个GridView,一个用于显示组,另一个用于显示组的成员。显示组的gridview有两列:description和buttonfield。当用户单击此字段中的按钮时,将显示一个新的gridview,其中包含组成员…好的,我已经测试过了,它似乎有效,现在我唯一的问题是,也许我也应该提到这一点,如何从另一个gridview传递@GroupDescription变量?我使用2个GridView,一个用于显示组,另一个用于显示组的成员。显示组的gridview有两列:description和buttonfield。当用户单击此字段中的按钮时,将显示一个新的gridview,其中包含组成员。。。