Find 2nd Highest salery in emp table
Select* from emp where &n=
select * count from emp where (salery >=emp.salery)
Enter n value 2
These query is correct or not. Tell me any other methods.
Answers were Sorted based on User's Feedback
Answer / asimananda
SELECT MAX(SAL) FROM EMP WHERE SAL < ( SELECT MAX(SAL) FROM
EMP )
| Is This Answer Correct ? | 7 Yes | 2 No |
Answer / kb
select top 1 * from emp
where sal < (select max(sal)from emp)
order by sal desc
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / lince
select top 1 * from (select distinct top 2 * from emp order by sal desc)t order by sal asc
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / r.rajivgandhi
Select max(salary) from emp where salary <(select max
(salary) from emp)
These Query is correct.Try It
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / madhu sudhan g
Hii lets consider the table Salary having EMPNO,EMPSal columns
to find the 2nd higest salary
;WITH CTE(Sal,Row)
AS
(
select EMPSal,ROW_NUMBER() OVER(ORDER BY EMPSal) as Row from Salary
)
select sal as Salary from CTE where Row=2
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ramu
by using sub quries we can do
select * from emp where sal=select max(sal) from emp where
sal<select max(sal) from emp;
| Is This Answer Correct ? | 1 Yes | 2 No |
What are the properties of sub-query?
Insert syudents details in table.Current system date &time insert into joining time.How do insert?( in sysdate only return current system date how do add time?)
what is integrated security (SSPI). why we use in the connection string?
Why I am getting "the microsoft .net framework 2.0 in not installed" message?
Do you know what is difference between index seek vs. Index scan?
What is @@Identity in sql?
what is raid? : Sql server database administration
What is sql server english query?
What is a Trace frag?Where can we use this?
What are subquery and its properties?
what's the difference between delete table and truncate table commands? : Sql server database administration
what are different types of backups available in sql server? Given a particular scenario, how would you go about choosing a backup plan? : Sql server database administration
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)