1)delete duplicates
By using temporary table, But it will delete exactly
duplicate rows NOT RECOMMANDABLE FOR HUGE TABLE. Query will
be.
SELECT DISTINCT * INTO #A FROM TABLE1
TRUNCATE TABLE TABLE1
INSERT INTO TABLE1
SELECT * FROM #A
2)second highest salary
select max(salary) from salary_table where salary in(select
top 2 salary from salary_table order by salary desc)
3)Receed identity
DBCC CHECKIDENT (orders, NORESEED)
To set the value of the next ID to be 1000, I can use this command:
DBCC CHECKIDENT (orders, RESEED, 999) 2 comments 8/1/10 by cooldude Delete
4) write query for fourth maximum salary from employee table using dense rank
select
distinct salary
from
(
select
DENSE_RANK() over(order by salary desc) as rnk,
salary
from
employee
) a
where
rnk = 4
sql interview question
http://allinterview.com/showanswers/131076.html
No comments:
Post a Comment