Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do not list duplicates, only one for each unique value

Status
Not open for further replies.

techkate

Programmer
Feb 23, 2004
118
US
I tried searching some threads, but wasn't quite sure that I chose the most appropriate keywords.

Say I have multiple records in a static table, but many have the same value for one field. For example:

ID Max
1 5
2 5
3 5
4 5
5 5
6 10
7 10
8 10
9 30
10 30
11 30
12 30

I'm trying to get this results set:

5
10
30

In other words, I'm trying to get one result for each unique 'Max' value

Is there a way to do this?

Thanks for you time.

 
What if I'm also retrieving other fields? Is there a way to filter for each distinct 'Max' field and ignore other fields?
 
You mean if you have:

Code:
ID   Max   SomeOtherField
1     5         a
2     5         a
3     5         b
4     5         b
5     5         c
6     10        d
7     10        d
8     10        e
9     30        f
10    30        f
11    30        g
12    30        g

and your query is:

SELECT DISTINCT MAX, SomeOtherFIeld From TableName

your results are going to be:
Code:
Max   SomeOtherField
5         a
5         b
5         c
10        d
10        e
30        f
30        g

because each of those combinations IS distinct

5 a is different than 5 b

Why don't you explain exactly what you are trying to do instead of me trying to read your virtual mind!

Even better, give me some example records and what you want your output to be and I'll try to come up with something that works for you.

les






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top