How do I Select only ONE of each item in my sql query?

I am selecting Distinct records from a query but in some cases it will pull the same record because something in the query is different. For example I am running a query to pull company names, the city they are in and the state they are in. The company has a unique ID and I want to select Distinct ID's not full records. The query returns the correct information but if the company has two addresses, then it will return the company twice. I want only one address to be shown. Each address has an Address Type, but if I limit it to a type, I do not get all the companies.
Brandon GarnettAsked:
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.

Guy Hengel [angelIII / a3]Billing EngineerCommented:

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
Your understanding of "distinct" is wrong I'm afraid.

"SELECT DISTINCT" is a "row operator",  meaning it decides "distinctiveness" over the whole row!!!

If you are using "SELECT DISTINCT" and then claiming it is returning duplicates, then you are using the wrong technique.

see: Select Distinct is returning duplicates ...

As I try to explain in that article, you have to decide what to do with the addresses; select distinct can't magically do it for you.

Guy's article (url above) shows some of the available techniques - but not all dbms platforms offer some of the solutions. For example Access does not offer the ROW_NUMBER() function.
Brandon GarnettAuthor Commented:
I've requested that this question be deleted for the following reason:

I found a way around the issue I was having
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
I have to disagree with the deletion, without concrete feedback and/or further questions to the experts...
Brandon GarnettAuthor Commented:
By using the min and max in my SQL query on address items I was able to select the items I wanted in specific columns into one row.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
and min() / max() techniques are explained in both articles...
hence, you should accept them as the answers, being tutorials giving you the general path to the solution you requested.
the "distinct" for queries is such a general and simple issue, you can learn that easily, which is why I had written the article
Brandon GarnettAuthor Commented:
The Min Max solution worked
Rob JurdEE Community AdvisorCommented:
Closed, 500 points refunded.
CS Moderator
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
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.