Saturday, April 11, 2015

Ditect duplicate rows in a Table in MS SQL

Here i have a table called Tbl_StuMarks. First we will Ditect duplicate rows

id   Name   Marks
———————----
1   Pritam   1000
2   Rintu     900
3   Rintu     900
4   Rintu     900
5   Lisa       800
6   Lisa       800
7   Lisa       800
8   Lisa       800
9   Anu       700
10 Anu       700
11 Gungun 600
12 Lisa       800
(To find duplicate Name wise)
Select Name, Marks from Tbl_StuMarks
group by Name, Marks Having count(Name)>1
(To find duplicate all column wise)
Select Name, Marks from Tbl_StuMarks
group by Name, Marks Having count(*)>1
Output
Name   Mark
--------------------
Rintu    900
Lisa      800
Anu      700

No comments:

Post a Comment