Back to Browse

Practice Activity - remove duplicate rows in SQL Server (three different ways)

15.3K views
Apr 7, 2022
6:44

Duplicate rows are very annoying. But how can you remove them in SQL Server? My SQL Server Udemy courses are: 70-461, 70-761 Querying Microsoft SQL Server with T-SQL: https://rebrand.ly/querying-microsoft-sql-server 98-364: Database Fundamentals (Microsoft SQL Server): https://rebrand.ly/database-fundamentals 70-462 SQL Server Database Administration (DBA): https://rebrand.ly/sql-server-dba Microsoft SQL Server Reporting Services (SSRS): https://rebrand.ly/sql-server-ssrs SQL Server Integration Services (SSIS): https://rebrand.ly/sql-server-ssis SQL Server Analysis Services (SSAS): https://rebrand.ly/sql-server-ssas-mdx Microsoft Power Pivot (Excel) and SSAS (Tabular DAX model): https://rebrand.ly/microsoft-powerpivot-ssas-tabular-dax ---- Duplicate rows may lead to erroneous conclusions, so often you will want them to be deleted. But how can you identify them? In this video, we'll have a look at three different ways at how we can get rid of them, using DISTINCT, GROUP BY, and UNION - but which is better? The starting code is: DROP VIEW IF EXISTS WithDuplicates GO CREATE VIEW WithDuplicates AS SELECT * FROM sys.objects UNION ALL SELECT * FROM sys.objects SELECT object_id, [name] FROM WithDuplicates ORDER BY object_id The code that I used in this video is: SELECT DISTINCT object_id, [name] FROM WithDuplicates ORDER BY object_id SELECT object_id, [name] FROM WithDuplicates GROUP BY object_id, [name] ORDER BY object_id SELECT object_id, [name] FROM WithDuplicates UNION SELECT object_id, [name] FROM WithDuplicates ORDER BY object_id

Download

1 formats

Video Formats

360pmp410.3 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Practice Activity - remove duplicate rows in SQL Server (three different ways) | NatokHD