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

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

 

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 .

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Published at DZone with permission of Technic Gang. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}