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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning smalest values in a query

Status
Not open for further replies.

mtl77

Programmer
May 27, 2003
31
0
0
CA
How do you get the smallest 10 values from a list of 20 in an SQL 200 query
 
Hi Raj,

Thanks for the help. The exact syntax is

SELECT DISTINCT TOP 10 myColumn FROM myTable ORDER BY myColumn

Cheers

 
Thanks mtl77,

i am not old here. So, just missed the syntax.

Thanks again for correcting it.


---
Raj
 
I just realized that the syntax will not work with what i'm using it for. I need the ten lowest numbers with duplication allowed, and distinct does not allow that.

Any thoughts?
 
SELECT TOP 10 myColumn FROM myTable ORDER BY myColumn DESC
 
Hi mtl77,

The query of jackfl give you the required results after you modify a little bit. That is just remove the DESC from the query and it will work.


---
Raj
 
That works Perfectly, thanks for the help Raj and Jackfl.
 
By the way, you can use the WITH TIES as part of the TOP N. Here's what it does:

DATA:

1
2
2
3

using TOP 3 returns:
1
2
2

using TOP 3 WITH TIES returns:
1
2
2
3

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top