Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write the query for find the top 2 highest salary in sql
server

Answer Posted / sums

Step1:
Create the "Salary" table,

Create table Salary
( Design_name varchar(20),
Basic_Sal int)

Step2:
Insert the values into "Salary" table,

Insert into Salary values('Office_Boy',4000)
Go
Insert into Salary values('Clerk',5000)
Go
Insert into Salary values('Head_Clerk',6000)
Go
Insert into Salary values('Accountant',7000)
Go
Insert into Salary values('Manager',8000)
Go
Insert into Salary values('PA',9000)
Go
Insert into Salary values('GM',10000)

Step3:
Write the Query aganist "Salary" table to find 'N'th
Maximum Basic Salary.

Query:

Select * from Salary s1 where (N =(select count(distinct
(s2.Basic_Sal)) from Salary s2
where s2.Basic_Sal>=s1.Basic_Sal))

N=1 --> Finds the first maximum Basic_sal
N=2 --> Finds the second maximum Basic_sal
N=3 --> Finds the Third maximum Basic_sal
.
.
.
N='N'--> Finds the 'N'th maximum Basic_sal

To find '2' maximum:

Select * from Salary s1 where (2=(select count(distinct
(s2.Basic_Sal)) from Salary s2
where s2.Basic_Sal>=s1.Basic_Sal))

Output:

Design_name Basic_sal

PA 9000

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is field in algebra?

980


Define a cross join?

952


explain what is raid and what are different types of raid configurations? : Sql server database administration

948


what is unique and xaml nonclustered index

995


What does this statement do @@rowcount?

923


What is ems sql management studio? : sql server management studio

1035


How is a full-text index updated?

895


Can we use having clause without group by?

929


Explain cursor as data base object?

973


what's new in sql server 2016?

905


Explain about integration services of Microsoft SQL server?

981


What are relationships and mention different types of relationships in the dbms

910


What is triggers and its types?

951


What is the difference between web edition and business edition?

111


What is resultset concur_updatable?

967