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

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

 

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 .

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

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