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 (2036)
 SQL Server interview questions  SQL Server Interview Questions (1076)
 MS Access interview questions  MS Access Interview Questions (24)
 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 (771)
 Databases AllOther interview questions  Databases AllOther Interview Questions (106)
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
 
what is the purpose of creating view is sql server 2000 Wipro 12
Is it possible to create a stored procedure that runs a query and outputs the results to a text file and allows me to add extra delimeters and static field info. If so How?   1
How to a Query to copy data from on table to another table. Cap-Gemini 4
hi i gone though satyam interview. what is Acid Properties? Satyam 2
what is differencial backup?how to work?Anybody explai it? HCL 2
Where are magic tables stored ? Is it in the same database where it is created ?   4
Difference between writing SQL query and stored procedure ? Cognizent 15
What are the differences between stored procedure and functions in SQL Server 2000? TCS 25
what is the difference between group and having give an example with query and sample output   6
Write the Syntax for Cursors. HP 2
What is Schema in Database? Cap-Gemini 1
Can we create nonclustered index in a table without creating a clustered index   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