ACCESS Query

Hi Experts,

I need to create a query that will return me all the unique records based on few fields. I am gonna try to explain by example.
here is a table with few columns  :
Table name : Contact
Fields name: Company, Address 1, address 2, City, State, district #
Company      Adress1                           address 2                      city                  state                 distric #
abc                 124 street                       222 door                        Miami             FL                      #03
abc                 123 street                       222 door                        Miami             FL                      #04
abc                 123 street                       222 door                        Miami             FL                      #02
abc                 123 street                       222 door                        Miami             FL                      #03
abc                 123 street                       222 door                        Miami             FL                      #04
abc                 123 street                       222 door                        Miami             FL                      #03
abc                 123 street                       222 door                        Miami             FL                      #03


the output will be
abc                 124 street                       222 door                        Miami             FL                      #03
abc                 123 street                       222 door                        Miami             FL                      #04
abc                 123 street                       222 door                        Miami             FL                      #02
abc                 123 street                       222 door                        Miami             FL                      #03

I would like a query that will show me all the unique company based on the fields : company , address 1 and district#.

I am trying to figure out how many unique company exists in a single district and have each district unique company on their own table.
Can someone help me ?

Thanks
tavernyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongSoftware Team LeadCommented:
just use Group By? like:

Select Company, Address 1, address 2, City, State, [district #]
from Contact
Group By Company, Address 1, address 2, City, State, [district #]

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tavernyAuthor Commented:
great that worked.
Thanks , I have another query  to design. It's gonna be a little more complicated .

I am gonna open another question now.

Thanks
bcnagelCommented:
Hi taverny.

Ryan Chong's suggestion is a good one. Because you indicated that you want uniqueness only on company, address1 and district #, I'd run a query like this one:

Select Company, [Address 1], [district #]
from Contact
Group By Company, [Address 1], [district #]

Open in new window


If you still want to return the address 2, City, State fields, you could run a summary function over them, like
Select Company, [Address 1], [district #], max([address 2]) as [address 2], 
max(City) as City, max([State]) as [State]
from Contact
Group By Company, [Address 1], [district #]

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.