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 (1080)
 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
 
is it possible to use a variable in a query with the IN clause (a,b,c..z), without getting quotes or conversion errors?   2
what is maximum size of temp db? iSoft 4
Advantages and Disadvantages of Cursor? Zenith 15
What is split brain scenario in DB mirroring?   1
what is the output for this query select * from employee where 1=1;   4
When we are using this query to shrink the log file,what exactly it will execute internally? Do we lose any data when we run this script? which data it will truncate in the log file and where it is saved. Please let me know... USE DatabaseName GO DBCC SHRINKFILE(<TransactionLogName>, 1) BACKUP LOG <DatabaseName> WITH TRUNCATE_ONLY DBCC SHRINKFILE(<TransactionLogName>, 1) GO Cognizent 1
table:employee EID ENAME MID(manager ids) 101 rama null 102 sita 101 103 siva 101 104 ganesh 103 . . . . . . for 103 ID the manager ID is 101(RAMA) and for 104 manager is SIVA if i give employee id (EID) you have to tell the manager for that EID write query? eample:if i give 102 .The query output should be manager for 102 ID that it should print RAMA as output   7
How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ........ in the emp database plz mail the answer @ mak2786@gmail.com Oracle 35
What is a Lock and let me know Different types of locks?   2
Difeerence between ssis 2005 and ssis2008? Convergys 1
What are indexes? When do you need to create Indexes? HP 4
When do we use the UPDATE_STATISTICS command?   4
 
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