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

Get the second smallest value

Status
Not open for further replies.

don2241

IS-IT--Management
Jun 1, 2001
57
AU
Hi!

Imagine having a table with attributes:
s#--p#--j#--qty

How can I get the second smallest value of 'qty'

Thank you
Martin
 
Try :-

set rowcount 1
select qty from tablename
where qty > (select min(qty) from tablename )
order by qty

(This suits sybase - your number of output rows may need different control)
;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Or you could say ...

select min(qty) from table
where qty > (select min(qty) from table)

Greg.
 
if you want another solution...

select distinct a.qty from table a
where 1=(select count(*) from table b where a.qty>b.qty)

it works in every dbms i know. web/sql developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top