Thursday, September 19, 2013

most frequently used sql queries

In the SQL query frequently most of the developers used the below query’s for day to day needs.

Get the top Nth value in the table.
--Get top 3 rd value
select min (salary) from EmpTable where Salary in (select top 3 salary from EMPTable)

How to select duplicate records in SQL.

--Select Duplicate value
select CName,count(*) from MyTable group by CName having count(*) >1

How to DELETE duplicate value from the Data TABLE using SQL Query.

--Delete dublicate value
delete from MyTable where ID not in(select MIN(ID) from MYTable group  by CName)

No comments: