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...
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-powerpiv...
----
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
Смотрите видео Practice Activity - remove duplicate rows in SQL Server (three different ways) онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь SQL Server 101 07 Апрель 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 12,385 раз и оно понравилось 139 людям.