etech0
asked on
Access aggregate query to concatenate all values
Can I have an aggregate query that will concatenate all applicable values, instead of summing or whatever?
For example, I have a camper table and a family table, with familyID in the camper table. I'd like a query that shows the family name, and then the camper's first names, all separated by commas.
Any ideas?
For example, I have a camper table and a family table, with familyID in the camper table. I'd like a query that shows the family name, and then the camper's first names, all separated by commas.
Any ideas?
ASKER
I tried the Concatenate function, but the concatenated column returns as blank!
SELECT FamilyT.ID, FamilyT.last_name, Concatenate("SELECT First_Name FROM campert
WHERE FamilyID = " & [ID]) AS FirstNames
FROM FamilyT;
You have two tables in your query. I believe his function works off of a single table. Your query should be something like:
SELECT FamilyT.ID, FamilyT.last_name, Concatenate("SELECT First_Name FROM FamilyT WHERE FamilyID = " & [ID]) AS FirstNames FROM FamilyT;
ASKER
However, last_name is in FamilyT, and first_name is in CamperT, along with FamilyID.
Should I make another query to base this one off of? Or can I use a subquery?
Should I make another query to base this one off of? Or can I use a subquery?
If the first names are in the camper table and not in the family table then you would need to create a query that has both and use that with the Concatenate function.
Looks like we cross posts. I guess you could try either. I myself haven't used this function but I'm sure it will work in at least 1 of those ways, if not both.
ASKER
Hmm. I tried this:
and still, the concatenated column is blank.
SELECT CamperFullNamesQ.ID, CamperFullNamesQ.last_name, Concatenate("SELECT First_Name FROM FamilyT WHERE FamilyID = " & [ID])
AS FirstNames
FROM CamperFullNamesQ;
and still, the concatenated column is blank.
Is CamperFullNamesQ a query that combines both? If so, then it should be:
SELECT CamperFullNamesQ.ID, CamperFullNamesQ.last_name, Concatenate("SELECT First_Name FROM CamperFullNamesQ WHERE FamilyID = " & [ID])
AS FirstNames
FROM CamperFullNamesQ;
ASKER
Still runs blank, though.
Can you upload your db without any privacy info?
ASKER
See attached. Thanks!
sample.accdb
sample.accdb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works great! Thanks
http://www.experts-exchang