Tuesday, August 20, 2013

Some SQL Query:Taken from net
nth salary in a table
SELECT * /*This is the outer query part */
FROM SPTestTable Emp1
WHERE (n-1) = ( /* Subquery starts here */
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM SPTestTable Emp2
WHERE Emp2.Salary > Emp1.Salary)

3rd highest salary
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 3 salary
FROM SPTestTable 
ORDER BY salary DESC) a

ORDER BY salary

Delete duplicate rows from a table.
select distinct * into #temp from SPTestTable truncate table SPTestTable insert SPTestTable select * from #temp drop table #temp

No comments:

Post a Comment