ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Databases >> SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions (2040)
 SQL Server interview questions  SQL Server Interview Questions (1082)
 MS Access interview questions  MS Access Interview Questions (25)
 MySQL interview questions  MySQL Interview Questions (194)
 Postgre interview questions  Postgre Interview Questions (6)
 Sybase interview questions  Sybase Interview Questions (22)
 DB Architecture interview questions  DB Architecture Interview Questions (5)
 DB Administration interview questions  DB Administration Interview Questions (213)
 DB Development interview questions  DB Development Interview Questions (53)
 SQL PLSQL interview questions  SQL PLSQL Interview Questions (775)
 Databases AllOther interview questions  Databases AllOther Interview Questions (107)
Question
1. How to fetch all the duplicate records from the table.

2. How to fetch the second highest salary from the table.
 Question Submitted By :: SQL-Server
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
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 ?    12 Yes 3 No
Kunal Gupta
 
Answer
# 2
2. Second highest salary from the table

select top 1 salary from emp where salary NOT IN
(SELECT MAX(salary) FROM emp)order by salary desc
 
Is This Answer Correct ?    3 Yes 0 No
Ashwini
 
 
 
Answer
# 3
(1) Query to fetch 2'nd highest salary:

Select max(sal) from emptable where sal not in (Select
max(sal) from emptable)

(2) How to fetch all the duplicate records from the table.

SELECT COUNT(*), <COLUMN_NAME> FROM EDUCATION GROUP BY
<COLUMN_NAME>
 
Is This Answer Correct ?    10 Yes 9 No
Amit Kumar
 
Answer
# 4
ANS 1:
select p.ColumnName from tablname p group by p.ColumnName

ans2:

Select min(salary)FROM emp WHERE (salary IN (SELECT
TOP 2 salary FROM emp ORDER BY salary DESC))
Or
Select top 1 salary from (select top 2 salary from emp
order by salary desc) emp order by salary
 
Is This Answer Correct ?    1 Yes 0 No
Rajkumar V
 
Answer
# 5
How to fetch the second highest salary from the table.
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 (n is always greater than one)
 
Is This Answer Correct ?    1 Yes 0 No
Saradhi
 
Answer
# 6
Ans:1
select Column_Name from Table_Name group by Column_Name
having count(Column_Name )>1

Ans:2
salary - column name

SELECT TOP 1 salary FROM (SELECT DISTINCT TOP 2 salary FROM
Table_Name ORDER BY salary DESC) A ORDER BY salary
 
Is This Answer Correct ?    1 Yes 0 No
Rajkumar V
 
Answer
# 7
select max(salary) from emp where salary<(select max(salary)
from emp)
 
Is This Answer Correct ?    2 Yes 2 No
Oracle.hemant
 
Answer
# 8
select max(salary) from employees where rownum<= 2
order by salary desc
 
Is This Answer Correct ?    0 Yes 0 No
Neelu
 
Answer
# 9
select salary from user order by salary desc LIMIT 1, 1 
Is This Answer Correct ?    0 Yes 0 No
Anbarasan K Kanagaraj
 
Answer
# 10
even i m suffering from this Q. plz let me knw? 
Is This Answer Correct ?    1 Yes 5 No
Jyoti
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
write sql program to get the detail of student in a class?   2
Questions regarding Raiseerror?   1
How we Resize table,temp table, database and log file size in SQL Server 2005 ABC 1
Can you explain the types of Joins that we can have with Sql Server?   2
why SQL server is more used to store database rather than Access   2
How to link up the text file to a Database table? Allianz 2
What are the OS services that the SQL Server installation adds?   2
How to provide Security for package? Convergys 1
I have a table in which phno is one of the columns.i do have some values in tht phno column.i need to update phno column values with 0(zero) as prefix.give me a correct solution plz... Value-Labs 7
WHAT IS UNIQUE IDENTIFIER DATA TYPE? Sparsh 2
how to implement locking in sql server Satyam 2
what is trigger NIIT 1
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com