473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to retrinve the first top salary hoder

karthickkuchanur
156 100+
Hai sir,
I want to retrive the top 3 salary hoder in my table
coloumn name=salary
Feb 14 '08 #1
18 3032
amitpatel66
2,367 Expert 2GB
Hai sir,
I want to retrive the top 3 salary hoder in my table
coloumn name=salary
Please post what you have tried so far?
Feb 14 '08 #2
karthickkuchanur
156 100+
Please post what you have tried so far?
select educationalhistorid from preducational order by educationalhistorid,limit 1,3
Feb 14 '08 #3
amitpatel66
2,367 Expert 2GB
select educationalhistorid from preducational order by educationalhistorid,limit 1,3
and what is the error that you are getting?
Feb 14 '08 #4
karthickkuchanur
156 100+
and what is the error that you are getting?
Error: ORA-00933: SQL command not properly ended
Feb 14 '08 #5
amitpatel66
2,367 Expert 2GB
Error: ORA-00933: SQL command not properly ended
Thats right because you cannot use LIMIT clause like that in SQL statement

Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT x.salary FROM emp x WHERE 3 > (SELECT COUNT(*) FROM emp WHERE salary > x.salary)
  3.  
  4.  
Feb 14 '08 #6
karthickkuchanur
156 100+
Thats right because you cannot use LIMIT clause like that in SQL statement

Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT x.salary FROM emp x WHERE 3 > (SELECT COUNT(*) FROM emp WHERE salary > x.salary)
  3.  
  4.  
thank u sir that query is working fine but i dobt how it is work,i have another doubt how can retrive the data from 3 to 10
Feb 14 '08 #7
amitpatel66
2,367 Expert 2GB
thank u sir that query is working fine but i dobt how it is work,i have another doubt how can retrive the data from 3 to 10
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT empno,salary FROM
  3. (SELECT empno,salary,dense_rank() OVER(ORDER BY SALARY DESC) rnk FROM emp) WHERE rn >= 3 AND rn <=10
  4.  
  5.  
Feb 14 '08 #8
karthickkuchanur
156 100+
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT empno,salary FROM
  3. (SELECT empno,salary,dense_rank() OVER(ORDER BY SALARY DESC) rnk FROM emp) WHERE rn >= 3 AND rn <=10
  4.  
  5.  
i cant able to uderstand the first query

This my query
SELECT x.EDUCATIONALHISTORYID FROM PREDUCATIONALHISTORY x WHERE 3 > (SELECT COUNT(*) FROM PREDUCATIONALHISTORY WHERE EDUCATIONALHISTORYID > x.EDUCATIONALHISTORYID)
i have 6 column

accourding to that how the condition sucess
3>(6) i can t sir
Feb 14 '08 #9
amitpatel66
2,367 Expert 2GB
i cant able to uderstand the first query
My first query is a correlated sub-query. You can see I am passing the value of the outer query table to the innser sub-query. So for each value of outer query, the sub-query will be executed.

Eg:

Salary:

1000
2000
3000
4000
5000

Now the execution happens this way:

First, 1000 is passed to the inner sub query and is compared with all the values of salary column, something like:

1000> 1000?, 2000> 1000?,.....till 5000 > 1000? -- From all this check, the count that you get for 1000 is 4, and check for the main WHERE condition, is 3 > 4?? -- No, so 1000 will not get listed in the output.

Same way for all other values, and the last three values that get listed in the output are: 3000, 4000, 5000 which gives you top three salaries

I hope my explanation is clear!!

Post back in case of any issues!!
Feb 14 '08 #10
Hai sir,
I want to retrive the top 3 salary hoder in my table
coloumn name=salary
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT min(sal)
  3. FROM (SELECT sal
  4. FROM emp 
  5. order by sal desc)
  6. WHERE rownum<(&nth_heighest+1); 
  7. //
  8.  
  9. select ename, sal
  10. from (select ename,sal,dense_rank() over(order by sal desc) dr from emp)
  11. where dr = &rnk
  12. //
  13.  
Feb 14 '08 #11
Hai sir,
I want to retrive the top 3 salary hoder in my table
coloumn name=salary
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT min(sal)
  3. FROM (SELECT sal
  4. FROM emp 
  5. order by sal desc)
  6. WHERE rownum<(&nth_heighest+1); 
  7. //
  8.  
  9. select ename, sal
  10. from (select ename,sal,dense_rank() over(order by sal desc) dr from emp)
  11. where dr = &rnk
  12. //
  13.  
Feb 14 '08 #12
karthickkuchanur
156 100+
My first query is a correlated sub-query. You can see I am passing the value of the outer query table to the innser sub-query. So for each value of outer query, the sub-query will be executed.

Eg:

Salary:

1000
2000
3000
4000
5000

Now the execution happens this way:

First, 1000 is passed to the inner sub query and is compared with all the values of salary column, something like:

1000> 1000?, 2000> 1000?,.....till 5000 > 1000? -- From all this check, the count that you get for 1000 is 4, and check for the main WHERE condition, is 3 > 4?? -- No, so 1000 will not get listed in the output.

Same way for all other values, and the last three values that get listed in the output are: 3000, 4000, 5000 which gives you top three salaries

I hope my explanation is clear!!

Post back in case of any issues!!
ok thank u very much sir
Feb 15 '08 #13
amitpatel66
2,367 Expert 2GB
ok thank u very much sir
you are welcome :) .
Feb 15 '08 #14
karthickkuchanur
156 100+
you are welcome :) .
1.
SELECT x.salary FROM emp x WHERE 3 > (SELECT COUNT(*) FROM emp WHERE salary > x.salary)


what is salary and x.salary (x is allias )
SELECT COUNT(*) FROM emp WHERE salary > x.salary)
count =6 according to my table
salary >x.salary means
1000>1000
how it is itterate sorry for any stupid queustion
Feb 15 '08 #15
amitpatel66
2,367 Expert 2GB
1.
SELECT x.salary FROM emp x WHERE 3 > (SELECT COUNT(*) FROM emp WHERE salary > x.salary)


what is salary and x.salary (x is allias )
SELECT COUNT(*) FROM emp WHERE salary > x.salary)
count =6 according to my table
salary >x.salary means
1000>1000
how it is itterate sorry for any stupid queustion
I think you are confused with the concept of correlated sub query. There is not iteration as such. Its like this:

For each value of outer query, the inner query is executed.

For example, The outer query table emp x (x is alias) has values 1000,2000,3000

Now, in the inner query, I am using the emp table, and there are 3 salary in the table ie 1000,2000,3000, so when the values of outer query are compared with the inner query values, then for all the values of outer query, the inner query will be executed.i.e. fthe value 1000 of outer query will be compared with all the values of inner query i.e. 1000,2000,3000, followed by same way for 2000,3000 of the outer query.

For more on correlated subqueries, check here
Feb 15 '08 #16
karthickkuchanur
156 100+
I think you are confused with the concept of correlated sub query. There is not iteration as such. Its like this:

For each value of outer query, the inner query is executed.

For example, The outer query table emp x (x is alias) has values 1000,2000,3000

Now, in the inner query, I am using the emp table, and there are 3 salary in the table ie 1000,2000,3000, so when the values of outer query are compared with the inner query values, then for all the values of outer query, the inner query will be executed.i.e. fthe value 1000 of outer query will be compared with all the values of inner query i.e. 1000,2000,3000, followed by same way for 2000,3000 of the outer query.

For more on correlated subqueries, check here
ok thanku very much sir i will try to learn the basic thing sir,but i am in situation to use the ur query blindly .thank u
Feb 16 '08 #17
amitpatel66
2,367 Expert 2GB
ok thanku very much sir i will try to learn the basic thing sir,but i am in situation to use the ur query blindly .thank u
Thats good to learn oracle basics.
You can also have a look at HOWTOS articles in our forum
Feb 18 '08 #18
with Test_CTE
as
(
SELECT firstname,totalamt,dense_rank() OVER(ORDER BY totalamt DESC) rn FROM [order]
)

select firstname,totalamt from Test_CTE where rn >3 and rn < 10
Sep 20 '10 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mark | last post by:
good spam subject ;). anyway, i'm alittle stumped. i'm in need of putting together a query that gets the next highest salary ( select max ( sal ) - 1?, from an emp_sal type table. another...
2
by: Deano | last post by:
OK, I'm working on a solution to the following problem but there are other ways to skin a cat as they say... Here's the table (simplified); ID EmployeeName SalaryAcc 1 Brown ...
1
by: sallyk57 | last post by:
Help with following Programs: Write two programs one where the performance rating here shoud be entered as a int where Excellent =1, Good= 2, Poor=3. an employee who is rated excellent will...
1
by: punkybrewster | last post by:
Basically my task is to write a program that computes and displays the weekly salaries of a company's salespeople based upon information entered by the user and that also displays the total for the...
5
by: james121285 | last post by:
This is to calculate an employees tax and pension. The salary is input from the keyboard. The NI contribution is calculated as 6% of the gross salary. The pension contribution is calculated as 2%...
8
by: hmmtn | last post by:
I would appreciate any help on this one. Assignment is as follows: Develop a program that will determine the gross pay for each of several employees. The company pays "straight time" for the first...
4
by: sonia.sardana | last post by:
I know how how to retrive the largest & second largest salary. tell me how to retrive the 3,4,5,...............Largest salary. Create table empl(empid int, empname varchar,salary int) insert...
8
by: mulugeta01 | last post by:
guys I have just started to learn c programing and i have some small assign ment to do . i cant go through , Please help, That is to calulate net salary after tax.1.gross salay = 78000 2.social...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.