Buy Questpond's video subscriptions on
huge discount
.
Online: 1310
Home
Articles
Interviews
Forums
For Beginners
Popular Questions
ITIL Career Advice
PMP Career Advice
Career Advices
Codes
Videos
ASP.NET
ASP.NET MVC
Android Intel XDK
Sql Server
AngularJS
Bootstrap
Backbone.JS
MongoDB
LESS (CSS)
jQuery
WPF
WWF
SSIS
LightSwitch
Tutorials
News
ASP.NET MVC
|
Be Interview Ready
|
Top Performers
|
DNF MVP
|
Top Posts
|
Winners
|
Subscribe
|
Catalogs
Welcome Guest !
Register
Login
Home
>
Codes
>
Loading ...
Calculate the second highest salary of an employee
Posted by
Srilu.Nayini577
under
Sql Server
category on
8/14/2012
|
Points: 40
| Views : 6138
Post Code
|
Search Codes
|
Code Home
select sal from employee where sal<(select max(sal) from employee)
Alert Moderator
Bookmark It
Comments or Responses
Posted by:
Gopesh9
on: 8/14/2012 Level:
Starter
| Status:
[Member]
|
Points: 10
It will give all the salary which will be less than the maximum salary. If You want only the 2nd highest salary then you will write
select max(sal) from employee where sal<(select max(sal) from employee)
Posted by:
Srilu.Nayini577
on: 8/14/2012 Level:
Starter
| Status:
[Member]
|
Points: 10
sorry for that.Actually i wrote squery as:
select max(sal) from employee where sal<(select max(sal) from employee)
by mistaken max keyword will be deleted.
Thank you,
Posted by:
Vikash
on: 8/14/2012 Level:
Starter
| Status:
[Member]
|
Points: 10
this is ok for second highest salary,but if i have to select 8th highest salary or 9th highest salary then this will not be feasible.......................
Posted by:
Gopesh9
on: 8/14/2012 Level:
Starter
| Status:
[Member]
|
Points: 10
@Vikash, You have to wite the C# code for that if you want the 8th or 9th highest salary...
Posted by:
Srilu.Nayini577
on: 8/14/2012 Level:
Starter
| Status:
[Member]
|
Points: 10
By sql server only we can calculate 8 th or 9th etc salary
Syntax:
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
Example:
If you want to calculate 9th highest sal put n=9;
SELECT TOP 1 sal
FROM (
SELECT DISTINCT TOP 9 sal
FROM Emp1
ORDER BY sal DESC) a
ORDER BY sal
If u want to find 10 ,u can put 10 inplace of n.
I think no need of c# code
Posted by:
Srilu.Nayini577
on: 8/14/2012 Level:
Starter
| Status:
[Member]
|
Points: 10
By sql server only we can calculate 8 th or 9th etc salary
Syntax:
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
Example:
If you want to calculate 9th highest sal put n=9;
SELECT TOP 1 sal
FROM (
SELECT DISTINCT TOP 9 sal
FROM Emp1
ORDER BY sal DESC) a
ORDER BY sal
If u want to find 10 ,u can put 10 inplace of n.
I think no need of c# code
Posted by:
Gopesh9
on: 8/14/2012 Level:
Starter
| Status:
[Member]
|
Points: 10
@srilu- By doing this you are giving extra load to the server, in a real time environment where you want to customize more and more so that the time will be minimized you have to use C# code in this case.
Posted by:
Srilu.Nayini577
on: 8/14/2012 Level:
Starter
| Status:
[Member]
|
Points: 10
Hi Gopesh,
Thank you for your advices .
Thank you,
Login to post response
Latest Code Snipptes
writing Custom pagination html code in python and django
Code snippet for setInterval
Azure Function - Connect to MS Dynamics using application user - .NET core 3.1
MS Dynamics 365- Custom action - Read input parameter values from plugin
MS Dynamics 365- Disassociate record from N-N relationship entity
Search box with icon in Navbar in bootstrap 4
Remove HTML tags using Regular Expression in C#
MS Dynamics 365- Close Quote from C# / Custom action
How to show and hide submenu in tabs using jquery
More ...