Prepare for your Next Interview
This is a discussion on DB2 query within the DB2 forums, part of the Databases category; How to retrieve the third maximum value from a column ? For Ex: If i have emp-id as one column with values 111,458,785,896,274,698 etc, using ...
|
|||
|
DB2 query
How to retrieve the third maximum value from a column ?
For Ex: If i have emp-id as one column with values 111,458,785,896,274,698 etc, using SELECT MAX(EMP-ID) retrieves the value "896". But i need to retrieve third maximum value ie., 698 incase of above example. How to write query for this ? |
| Sponsored Links |
|
|||
|
Re: DB2 query
Query to select top nth record:
consider the table name as emp,then select empid from emp e1 where ( n = ( select count ( distinct ( e2.empid ) ) from emp e2 where e2.empid >=e1.empid)) replace n by 3 to get the third maximum |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Query | sakshi_2801 | SQL | 4 | 08-06-2007 10:29 AM |
| regarding sql query | psuresh1982 | SQL | 8 | 07-13-2007 03:20 AM |
| Query | jescalante | Oracle | 4 | 06-25-2007 02:13 AM |
| Query | K.K.Rajiv | SQL | 2 | 05-29-2007 10:41 PM |
| Query with C++ | StephenRaj | C and C++ | 1 | 08-14-2006 04:09 AM |