Avatar of etech0
etech0
Flag 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?
Microsoft Access

Avatar of undefined
Last Comment
etech0

8/22/2022 - Mon
IrogSinta

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
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

IrogSinta

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

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
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?
IrogSinta

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.
IrogSinta

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
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.
IrogSinta

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

etech0

ASKER
Still runs blank, though.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
IrogSinta

Can you upload your db without any privacy info?
etech0

ASKER
See attached. Thanks!
sample.accdb
ASKER CERTIFIED SOLUTION
Patrick Matthews

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
etech0

ASKER
That works great! Thanks
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.