Download presentation
Presentation is loading. Please wait.
Published byRitva Laine Modified over 6 years ago
1
SQL Server How to find duplicate values with T-SQL
HeelpBook © 14/04/2019 SQL Server How to find duplicate values with T-SQL Source: Link Posted By: HeelpBook Permalink: Link 14/04/2019 How-Tos <<
2
HeelpBook © 14/04/2019 With the SQL statement below you can find duplicate values in any table, just change the tablefield into the column you want to search and change the table into the name of the table you need to search. In your recordset you will see the tablefield and how many times it is found as a duplicate. 14/04/2019 >> How to find duplicate values with T-SQL How-Tos <<
3
HeelpBook © 14/04/2019 SELECT tablefield, COUNT(tablefield) AS dup_count FROM table GROUP BY tablefield HAVING (COUNT(tablefield) > 1) 14/04/2019 >> How to find duplicate values with T-SQL How-Tos <<
4
>> How to find duplicate values with T-SQL How-Tos <<
HeelpBook © 14/04/2019 Some further tempering with the statement gets the complete records that are double. (yeah yeah.. no * should be used in the SELECT) It's just for demonstrating folks!! SELECT * FROM table WHERE tablefield IN ( SELECT tablefield FROM table GROUP BY tablefield HAVING (COUNT(tablefield ) > 1) ) 14/04/2019 >> How to find duplicate values with T-SQL How-Tos <<
5
HeelpBook © 14/04/2019 To go even further in the process and DELETE every double record we could do something like make a temporary table Insert the double records, delete it from the original table and insert the saved single records from the temporary table. 14/04/2019 >> How to find duplicate values with T-SQL How-Tos <<
6
HeelpBook © 14/04/2019 That’s all Folks Come visit us on to find and read more documents and guides… AND / OR Subscribe to our feed RSS: Link Or see&read us on FeedBurner: Link { 14/04/2019 >> How to find duplicate values with T-SQL How-Tos <<
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.