I have a table table1 with 1 millions rows of data.
I want to remove all the duplicate records in the table1
I was looking at this link:
How do I remove duplicate records in a join table in PostgreSQL?
Can you tell me how to do this below query in SQL server?
DELETE FROM questions_tags q
WHERE EXISTS (
SELECT 1
FROM questions_tags q1
WHERE q1.ctid < q.ctid
AND q.question_id = q1.question_id
AND q.tag_id = q1.tag_id
);
Best Answer
The syntax is just slightly different:
Personally, I prefer to use a CTE. Then I can easily swap in a
SELECT
to validate what I am about to delete, and easily change the where clause to validate what I am going to keep:Then, of course, add a proper key constraint before you let anybody insert any new nonsense into this table.