You can't delete the record as there is no uniqueness in your records.
So can select the records without duplicating the records.
Refer below query.
SQL
CREATE TABLE #Class1
(
name VARCHAR(50),
class VARCHAR(50)
)
INSERT INTO #Class1(name, class) VALUES ('A', 'First')
INSERT INTO #Class1(name, class) VALUES ('A', 'Second')
INSERT INTO #Class1(name, class) VALUES ('B', 'First')
INSERT INTO #Class1(name, class) VALUES ('A', 'Third')
INSERT INTO #Class1(name, class) VALUES ('B', 'First')
INSERT INTO #Class1(name, class) VALUES ('A', 'First')
SELECT name, class
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY name,class ORDER BY (select 0)) Number,
name, class
FROM #Class1
)p
WHERE Number = 1
OR
SELECT DISTINCT name, class from #class1
Output
name |
class |
A |
First |
A |
Second |
A |
Third |
B |
First |