Link to home
Start Free TrialLog in
Avatar of etech0
etech0Flag for United States of America

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?
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Try checking out Duane Hookum's Concatenate function or the MakeCSV function in this thread:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_27726014.html#a37994404
Avatar of etech0

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;

Open in new window

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;

Open in new window

Avatar of etech0

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?
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.
Avatar of etech0

ASKER

Hmm. I tried this:

SELECT CamperFullNamesQ.ID, CamperFullNamesQ.last_name, Concatenate("SELECT First_Name FROM FamilyT WHERE FamilyID = " & [ID])
 AS FirstNames
FROM CamperFullNamesQ;

Open in new window


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;

Open in new window

Avatar of etech0

ASKER

Still runs blank, though.
Can you upload your db without any privacy info?
Avatar of etech0

ASKER

See attached. Thanks!
sample.accdb
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of etech0

ASKER

That works great! Thanks