View previous topic :: View next topic
|
Author |
Message |
jajularamesh
New User
Joined: 21 Nov 2005 Posts: 8
|
|
|
|
i want to select the top n employees (based on salary) in the organization |
|
Back to top |
|
|
nikyojin
New User
Joined: 05 Oct 2005 Posts: 94
|
|
|
|
Query :-
Code: |
Select * from tablename
Order By Sal Asc/Desc
Fetch first n rows only; |
Choose the values Asc/Desc as per ur requirements and do include required details prior to posting ur queries. |
|
Back to top |
|
|
khamarutheen
Active Member
Joined: 23 Aug 2005 Posts: 677 Location: NJ
|
|
|
|
Hi frnd,
Code: |
SELECT ENO,ENAME,SALARY
FROM EMP
FETCH FIRST/LAST N ROWS ONLY |
As per nikyojin u can also use order by clause as per ur need..... |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Query given by nikyojin is correct, with out using ORDER BY its not always possible to receive values for TOP employees.
With out ORDER BY clause it'll simply return mentioned FIRST/LAST rows.
Regards,
Priyesh. |
|
Back to top |
|
|
nrsmca
New User
Joined: 25 May 2005 Posts: 14
|
|
|
|
N-th max. list:-
1.Select * from tablename A where Num_var > (Select count(*) from ablename B where B.Salary > A.Salary);
We should 2 (>) for ur query...
or
2.Select * from tablename C where C.salary >=(
Select A.salary from tablename A where Num_var = (Select count(*) from ablename B where B.Salary >= A.Salary));
or
3.Select * from Tablename where row_num <= Num_var order by salary;
N-th min. list:-
1.Select * from tablename A where Num_var < (Select count(*) from ablename B where B.Salary < A.Salary);
Plz. Modify (2) & (3) ... as same as the (1).
Thanks,
Rajasekaran.N |
|
Back to top |
|
|
|