How to Delete Duplicate Records from a SQL Table

How to Delete Duplicate Records from a SQL Table

Matador Software

1 год назад

2,173 Просмотров

Learn how to use a CTE to delete duplicate rows from a SQL Table. I'll be demonstrating this in SQL Server but the concepts are universal across most Relational Database Management Systems.

We will cover the CTE syntax, the ROW_NUMBER() Window Function and assigning flags within partitioned rows.

Enjoy!

🤝 Follow my Data content on Twitter:

https://www.twitter.com/matadorsoftware

🤝 I’m also sharing Data knowledge on Instagram:

https://www.instagram.com/matador_sof...

🤝 Connect with me on LinkedIn:

https://www.linkedin.com/in/ja376

🤝 View my Website:

https://www.matadorsoftware.me

Тэги:

#sql #sql_server #mysql #postgresql #database #data #data_analysis #business_intelligence #sql_duplicates #duplicate_records #data_wrangling
Ссылки и html тэги не поддерживаются


Комментарии:

@faresyounis8999
@faresyounis8999 - 18.02.2023 13:20

That was super useful, thank you so much for your knowledge-sharing.

Ответить
@MaceGee31
@MaceGee31 - 23.01.2023 19:59

Nice Video, helped me with my case.

Just some addition for everyone looking forward to use your method but they dont have only one primary key, like your EmployeeID.

just add those to your PARTITION BY function separated by comma. f.e.:

ROW_NUMBER() OVER (PARTITION BY FirstName,LastName,Deparment ORDER BY FirstName)

Ответить
@hasanmougharbel8030
@hasanmougharbel8030 - 17.09.2022 09:58

Hello man,
god bless your efforts.
A have a general enquiry as a new sql learner.
When i apply INSERT, UPDATE, or DELETE statement inside sql management studio, is the commit statement applied implicitly as part of the three former commands. The reason that i want to
make sure that when these three commands being applied would take effect on the database directly and at same time for all users.
Thanks for assisting me with my enquiry.

Ответить
@surojeetghosh8389
@surojeetghosh8389 - 15.09.2022 19:29

Great video james.hope to learn more from you.came to ur channel after we connected on LinkedIn.hope to become as good as u In sql oneday.

Ответить
@mariasfiles7777
@mariasfiles7777 - 14.09.2022 05:13

Thank you

Ответить
@flexyourdata
@flexyourdata - 12.09.2022 23:37

TIL DELETE FROM CTE. Thanks for sharing!

Ответить