This must be a very common task for you SQL programmers:
My users can belong to two groups... so I created a Table Users and Groups.
Users have two Group Ids (Foreighn keys) in a relationship with the Group Primary key, described next:
Table Users
PK UserId
FK GrpId1
Fk GrpId2
UserName
Table Group
PK GrpId
GrpName
Now I created 3 queries:
SELECT Group.GrpName AS Grp1Name
FROM Group INNER JOIN
Users ON Group.GrpId = Users.Grp1Id
WHERE (Users.UserId = @UserId)
SELECT Group.GrpName AS Grp2Name
FROM Group INNER JOIN
Users ON Group.GrpId = Users.Grp2Id
WHERE (Users.UserId = @UserId)
SELECT UserName, Grp1Id, Grp2Id
FROM Users
WHERE (UserId = @UserId)
How do I get a final record with
UserName, Grp1Id, Grp1Name, Grp2Id, Grp2Name
My users can belong to two groups... so I created a Table Users and Groups.
Users have two Group Ids (Foreighn keys) in a relationship with the Group Primary key, described next:
Table Users
PK UserId
FK GrpId1
Fk GrpId2
UserName
Table Group
PK GrpId
GrpName
Now I created 3 queries:
SELECT Group.GrpName AS Grp1Name
FROM Group INNER JOIN
Users ON Group.GrpId = Users.Grp1Id
WHERE (Users.UserId = @UserId)
SELECT Group.GrpName AS Grp2Name
FROM Group INNER JOIN
Users ON Group.GrpId = Users.Grp2Id
WHERE (Users.UserId = @UserId)
SELECT UserName, Grp1Id, Grp2Id
FROM Users
WHERE (UserId = @UserId)
How do I get a final record with
UserName, Grp1Id, Grp1Name, Grp2Id, Grp2Name