View previous topic :: View next topic
|
Author |
Message |
rajrohith
New User
Joined: 15 Apr 2005 Posts: 54 Location: chennai
|
|
|
|
hai all
i have doubt
i want to query
find a second max row and 5th max row
how we write a query
by
raj |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post some sample data and what you need the output to be. |
|
Back to top |
|
|
rajrohith
New User
Joined: 15 Apr 2005 Posts: 54 Location: chennai
|
|
|
|
just take one table
it contain so many records
filed is empname, salary, dept
i want who is second highest salary person
and another who is 5 th highest salary person
by
raj |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
I bet this one is going to top the list of popularity amongst regular questions being asked.
Take a look here... Previously Discussed...
Also it might help others if you use SEARCH facility before posting your questions. |
|
Back to top |
|
|
rajrohith
New User
Joined: 15 Apr 2005 Posts: 54 Location: chennai
|
|
|
|
Code:
SELECT MAX(SALARY) FROM EMP_TABLE A WHERE 5=(SELECT COUNT(*) FROM EMP_TABLE B WHERE A.SALARY<=B.SALARY);
For Nth Maximum Value:-
Code:
SELECT SALARY FROM EMP_TABLE A WHERE (N-1) IN (SELECT COUNT(*) FROM EMP_TABLE B WHERE A.SALARY < B. SALARY);
i have one table only not two tables
i have little bit confuse here how it comes table
B
my query is only one table not from two tables
i want to reterive the data from one table A only
by
raj |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Raj,
Quote: |
my query is only one table not from two tables
i want to reterive the data from one table A only |
Did you execute the query or NOT?
Its not two tables... Its just kind of image of a single table... I would not go in further details of ALIAs, which is what this called... |
|
Back to top |
|
|
|