Over a million developers have joined DZone.

How to Remove Duplicate Rows in SQL Server 2008

· Java Zone

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

 

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 .

Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.

Topics:

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}