1. How to fetch all the duplicate records from the table.

2. How to fetch the second highest salary from the table.

Answer Posted / kunal gupta

These are the easiest and best queries and 100% tested.

1) 2nd highest salary


select top 1 sal from (Select top 2 sal from emp group by
sal order by sal desc) e order by sal


like wise you can find n highet salar(e.g 5th largest 6th
largest)

select top 1 sal from (Select top [n] sal from emp group by
sal order by sal desc) e order by sal


2) fetch all duplicated records from the table

e.g If table has three columns named 'col1', 'col2'
and 'col3'

select col1, col2, col3 from tbl group by col1, col2, col
having count(col1)>1

Is This Answer Correct ?    13 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the advantage of sql server?

542


Do you know what is difference between index seek vs. Index scan?

519


Which tcl commands are available on the sql server?

607


Explain cursor as data base object?

576


How to call a function from a stored procedure in SQL Server ?

549






What is log shipping? Can we do logshipping with SQL Server 7.0 - Logshipping is a new feature of SQL Server 2000. We should have two SQL Server - Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan.

2312


What is the purpose of update statistics and scope_identity() function?

597


what do you understand by change data capture?

558


How to create an identity column?

637


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

583


What are the functions in sql server?

543


What is #table in sql server?

534


What do you understand by user-defined function in the sql server?

490


How many types of built in functions are there in sql server 2012?

490


Do you know concepts and capabilities of sql server?

583