Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


1. How to fetch all the duplicate records from the table.

2. How to fetch the second highest salary from the table.

Answers were Sorted based on User's Feedback



1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / 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

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / ashwini

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

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / rajkumar v

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 ?    2 Yes 0 No

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / amit kumar

(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

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / rajkumar v

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

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / saradhi

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

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / oracle.hemant

select max(salary) from emp where salary<(select max(salary)
from emp)

Is This Answer Correct ?    2 Yes 2 No

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / neelu

select max(salary) from employees where rownum<= 2
order by salary desc

Is This Answer Correct ?    0 Yes 0 No

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / sneha s

fetch duplicate records from table:
select column_name from table_name group by column_name having count(column_name)>1;

get the second highest salary:
select distinct salary from emp order by salary desc limit 1,1;

Is This Answer Correct ?    0 Yes 0 No

1. How to fetch all the duplicate records from the table. 2. How to fetch the second highest sala..

Answer / anbarasan k kanagaraj

select salary from user order by salary desc LIMIT 1, 1

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SQL Server Interview Questions

What is ms sql server triggers?

0 Answers  


How can you list all the table constraints in a database?

0 Answers  


Explain what is the use of custom fields in report?

0 Answers  


Can sql servers link to other servers?

0 Answers  


Explain features of analysis services?

0 Answers  


Can a unique index be created on a column, which contains null?

0 Answers  


find 2nd highest salary of person using cursor concept?

6 Answers   HCL,


What command is used to rename the database?

0 Answers  


What does this statement do @@rowcount?

0 Answers  


What is difference between views and stored procedures?

0 Answers  


CTE(common table expression)

1 Answers   Thomson Reuters,


9. Write a query to list a new column with the difference in temp of the cities Delhi and Mumbai, Mumbai and Jammu and soon. Consider the following table : City_id City Temp. 1 delhi 40 2 Mumbai 35 3 Jammu 32 4 Pune 18

2 Answers  


Categories