evergrean100
Technical User
I have an Access 2003 database with these example values:
I am trying to fetch the distinct names with their city/cities output:
Jones -> San Diego, Oakland, San Francisco
Carson -> San Diego, San Francisco
Baker -> Oakland
Nimmons -> Los Angeles
Smith -> Los Angeles
My attempt below seems very long and cant seem to put the city field in my query because it gives me errors saying its not part of aggregate function. I also tried UNION ALL and that didnt work. Please advise.
Code:
id NameOne NameTwo city
1 Jones Carson San Diego
2 Baker Jones Oakland
3 Nimmons Smith Los Angeles
4 Jones Carson San Francisco
Jones -> San Diego, Oakland, San Francisco
Carson -> San Diego, San Francisco
Baker -> Oakland
Nimmons -> Los Angeles
Smith -> Los Angeles
My attempt below seems very long and cant seem to put the city field in my query because it gives me errors saying its not part of aggregate function. I also tried UNION ALL and that didnt work. Please advise.
Code:
select distinct NameOne, max(TableOne.id) as mydata
from TableOne
group by NameOne
UNION
select distinct NameTwo, max(TableOne.id) as mydata2
from TableOne
group by NameTwo