Logo 
Search:

SQL Server Article

Submit Article
Comments on Eliminating Duplicate Rows with DISTINCT
Category: SQL Server (Miscellaneous)    Author: Sarita Patel

This article specifies the significance of DISTINCT keyword in sql sever.


Shruti Sharma
Shruti Sharma from United StatesMar 31

DELETE
FROM TableName
WHERE ColumnId NOT IN
(
SELECT MAX(ColumnId)
FROM TableName
GROUP BY LTRIM(RTRIM(ColumnDuplicate)))


Here,
TableName - Table name from which you want to remove duplicate rows.
ColumnId - Primary Key column which has unique value.
ColumnDuplicate - It is Column name which contains duplicate values.


Example: Following example will delete all rows with duplicate title in Forum table.

DELETE
FROM Forum
WHERE ForumId NOT IN
(
SELECT MAX(ForumId)
FROM Forum
GROUP BY LTRIM(RTRIM(ForumTitle)))
Lintin Maryson
Lintin Maryson from IndiaMar 31
good point...
Will you please tell me the syntax for removing duplicate values without using distinct keyword.... waiting for your kind replay..
thank you...........


Please enter your Comment
  • Comment should be atleast 15 Characters.
  • Please put code inside [Code] your code [/Code].