S
samearle
I need to write a SQL statement that essentially joins two tables.
"Users" and "UsersInGroup".
Users has a one to many relationship with UsersInGroup.
But I want the query to return only one record for each record in
Users, with all instances of that record in UsersInGroup - the many
relationship - to be concatinated onto the single querry record.
Right now I can get all the data:
SELECT Users.*,
UserInGroup.GroupID
FROM Users
INNER JOIN UserInGroup
ON Users.UserID = UserInGroup.UserID;
but for each new GroupID for each UserID it adds a new record. I'd like
it to only return one record per UserID, with all GroupID's added to
that user.
Tried this, but still can't get it:
SELECT u.UserID,
DMax("[GroupID]"," UserInGroup","GroupID = 1") AS group_1,
DMax("[GroupID]"," UserInGroup","GroupID = 2") AS group_2,
DMax("[GroupID]"," UserInGroup","GroupID = 3") AS group_3
FROM Users AS u, UserInGroup AS g
WHERE (((u.UserID)=[g].[UserID]) AND ((g.GroupID) In (1,2,3)))
GROUP BY u.UserID;
Thanks for the help.
Sam
"Users" and "UsersInGroup".
Users has a one to many relationship with UsersInGroup.
But I want the query to return only one record for each record in
Users, with all instances of that record in UsersInGroup - the many
relationship - to be concatinated onto the single querry record.
Right now I can get all the data:
SELECT Users.*,
UserInGroup.GroupID
FROM Users
INNER JOIN UserInGroup
ON Users.UserID = UserInGroup.UserID;
but for each new GroupID for each UserID it adds a new record. I'd like
it to only return one record per UserID, with all GroupID's added to
that user.
Tried this, but still can't get it:
SELECT u.UserID,
DMax("[GroupID]"," UserInGroup","GroupID = 1") AS group_1,
DMax("[GroupID]"," UserInGroup","GroupID = 2") AS group_2,
DMax("[GroupID]"," UserInGroup","GroupID = 3") AS group_3
FROM Users AS u, UserInGroup AS g
WHERE (((u.UserID)=[g].[UserID]) AND ((g.GroupID) In (1,2,3)))
GROUP BY u.UserID;
Thanks for the help.
Sam