Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a table in access of 42,000 plus rows which contains

column1 = City Column2 = State Column3 = zip

Now it has multiple rows for cities with multiple zips. SO you could have have four rows as such: (Note Raleigh is Column1, NC is Column2, and 29706 is Column3)

Raleigh NC 29706
Raleigh NC 29707
Raleigh NC 29708
Raleigh NC 29709

I want to search the table and return the City State one time as such "Raleigh NC" with all the zips that are related to it in a single column in a query (IE: result being like such)

Raleigh NC 29706 29707 29708 29709

I have been trying to accomplish this for a week now and have found tons of concats and such but none seem to remove the duplicate cities and list the zips in the same cell with the city state as one column record.

Any help would be greatly appreciatted.

share|improve this question

1 Answer 1

Good problem. I don't know Access, but this article seems to tackle the problem in SQL rather nicely. Perhaps you can inspire yourself with some of the techniques if you familiar with it.

Anyhow, the solution appear to revolve around two things:

  1. First have a unique list of cities (in SQL this is done by select city, state group by city, state). Then find a way to create a query that assigns a unique row number (1,2,3,) to every zip for a given city, and then query that query to concatenate using case(1) + case(2), etc. This is the first solution in the article.
  2. Use VBA to make a function for it.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.