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

Are you joining the containers revolution? Start leveraging container management using Platform9's ultimate guide to Kubernetes deployment.

 

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 .

Moving towards a private or Hybrid cloud infrastructure model? Get started with our OpenStack Deployment Models guide to learn the proper deployment model for your organization.

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 }}