How to find the second largest salary in the emp database and
also How to find 3rd,4th and so on ........ in the emp database
plz mail the answer @ mak2786@gmail.com
Answers were Sorted based on User's Feedback
Answer / your name
Forget everything...Here it goes..in a simple way...
Select salary from tbl_name a where
n = (Select count(distinct(count(*))) from tbl_name b
where b.salary>=a.salary)
Substitute you value for n. thats all.
| Is This Answer Correct ? | 0 Yes | 1 No |
SELECT EmpId,Salary
FROM(SELECT ROW_NUMBER() OVER(ORDER BY Salary Desc) AS [ROW_NUMBER],* FROM (SELECT DISTINCT Salary,Empid FROM EMPDetails)Emp)Emp1
WHERE ROW_NUMBER BETWEEN 2 AND 5
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / prasant palo
with ttble as
(
select top 3 empid,empname,empsalary
from
emptable
order by empsalary desc
)
-- above will create a common table expression with name
--ttable
-- to know about it search for commontable expression
select top 1 empid,empname,empsalary
from
ttable
order by empsalary asc
| Is This Answer Correct ? | 2 Yes | 5 No |
Answer / prashant narvekar
1. solution taken as std_id instead of salary
select max( b.std_id) from std_info a
inner join std_info b on a.std_id <> b.std_id
where a.std_id > b.std_id
2. solution
select max(std_id) from std_info
where std_id < ( select max(std_id) from std_info)
| Is This Answer Correct ? | 2 Yes | 5 No |
Answer / savita vishwakarma
select max(sal)
from (select rownum
from emp
order by sal desc)
where rownum=2
| Is This Answer Correct ? | 2 Yes | 5 No |
Answer / vishakha shrivastava
for second largest salary
Select * from emp a where 2=(select count(*) from emp b
where a.sal<=b.sal)
Above mentioned query can also be used for 3 ,4 ..n
Select * from emp a where 3=(select count(*) from emp b
where a.sal<=b.sal)
| Is This Answer Correct ? | 2 Yes | 5 No |
Answer / vinay singh
To find any number of Salary..
Select * From Table E1 Where
(n-1) = (Select Count(Distinct(E2.Sal)) From Table E2
Where E2.Sal> E1.Sal)
**Vinay Singh
| Is This Answer Correct ? | 8 Yes | 12 No |
Answer / balaji
TO FIND THE N-1th HIGHEST SALARY IN EMP TABLE
Select Min(salary) from emptable where salary not in(Select
Min(salary) from emptable)
| Is This Answer Correct ? | 0 Yes | 4 No |
Answer / subhranghshu bhattacharjee
another way u can find 2nd largest salary,3rd largest
salary ... so on
select sal from(select sal from emp order by sal desc)
where rownum<3
minus
select sal from(select sal from emp order by sal desc)
where rownum<2
only change rownum to find various largest salary
Subhranghshu Bhattacharjee
| Is This Answer Correct ? | 4 Yes | 9 No |
What are the differences between ms sql server & oracle?
you want to be sure that queries in a database always execute at the maximum possible speed. To achieve this goal you have created various indexes on tables which other statement will keep the database in good condition? : Sql server administration
Why people hate cursor?
hi. suppose one person goal is strong knowledge on SQL.... suggest me ...if he learns SQL SERVER or ORACLE? which is best?
7 Answers Google, TCS, Unisys,
What are the encryption mechanisms in sql server?
What is query and its types?
You are designing a database for your human resources department in the employee table, there is a field for social security number, which cannot contain null values if no value is given, you want a value of unknown to be inserted in this field what is the best approach?
in tabase table having a column in it empname field is there which having 5 duplicate values is there i want deleted all the duplicates i want showing only one name only.
employee table has employee id ----------- empid ---------------- 1 2 3 3 3 4 5 5 5 6 6 6 7 here the values r repeated two times.how to select the repeated values only.i.e 3,5,6 should alone come.
Diffrences between sql server 2000 vs 2008
What are temporal tables in sql server 2016?
How to get the definition of a user defined function back?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)