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
What is the difference between functions and scalar functions?
What is implicit mode in sql server?
Define left outer join in sql server joins?
How to create an multi-statement table-valued function?
Explain error and transaction handling in sql server?
how to invoke a trigger on demand? : Sql server database administration
What is SQL Azure Fabric?
Can we use max in where clause?
What is a fill factor?
What is 3nf normalization form?
Tell me what is use of except clause? How it differs from not in clause?
Do you know how to implement service broker?
what is a join and explain different types of joins? : Sql server database administration
What are the disadvantages of merge replication?
How would you choose between a clustered and a non-clustered index?