Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Remove Duplicate Rows in SQL Server 2008

DZone's Guide to

How to Remove Duplicate Rows in SQL Server 2008

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

 

How to remove duplicate rows in sql server 2008

To remove duplicate rows in SQL use group by clause  with having function.

For example

Create table Result with following data

Column name

Datatype

Allow null

RollNumber

Int

no

Subject

Char (10)

no

Marks

int

no

RollNumber

Subject

Marks

1001

Physics

80

1001

Chemistry

75

1001

Physics

80

1002

Chemistry

60

To find duplicate entry in result table

Select rollnumber, subject, marks, count (*) as count from result group by rollnumber, subject, marks having count (*) > 1

Rollnumber

Subject

Marks

Count

1001

Physics

80

2


Thus using Having Clause we easily identify duplicate rows .

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}