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
How to create dbo table in sql server?
What methods do you follow to protect from sql injection attack?
What is temporary table in sql server? Why we use temp table?
What is the maximum number of index per table?
What is the difference between lock, block and deadlock? : sql server database administration
Why do we need normalization?
How can you list all the columns in a database?
What is merge?
Explain about temporary stored procedure?
Can you get second highest salary from the table?
What are the differences between char and nchar in ms sql server?
What are the advantages of mirroring?
If we delete pack Spec what will be the status of pack Body ?
What are user-defined functions (udfs) in sql server?
When multiple after triggers are attached to sql table, how to control the order of execution?