Saturday, April 11, 2015

Remove duplicate rows in a Table using %%physloc%%

Here i have a table called Tbl_StuMarks.

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
DELETE
FROM Tbl_StuMarks a
WHERE a.%%physloc%%
NOT IN (SELECT MIN(b.%%physloc%%)
FROM Tbl_StuMarks b
GROUP BY b.Name, b.Marks);
—————–(Now check the table)——————-
SELECT * from Tbl_StuMarks
Output
id   Name   Marks
————————
1   Pritam   1000
2   Rintu     900
5   Lisa       800
9   Anu       700
11 Gungun 600

2 comments: