Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Show Duplicate Records

Posted on February 28, 2013October 26, 2015 By David Kittell

These two queries run under different schools of thought and purpose but will help in finding duplicate records.

First, if you only want to see the records that are duplicates and the amount of times they appear in the table you could run this code:

SELECT
	memberid
	,COUNT(*) AS No_Of_Occurrences
FROM
	table
GROUP BY
	memberid HAVING COUNT(*)>1
ORDER BY
	memberid

Second, if you want to see all duplicate records along with their id or other information in the table you could run this code:

SELECT
	id, memberid
FROM
	table
WHERE
	memberid
		IN
			(
				SELECT
					memberid
				FROM
					table
				GROUP BY
					memberid HAVING COUNT(*)>1
			)
ORDER BY
	memberid, id

Third

SELECT *
FROM Members HLM1
INNER JOIN (
	SELECT MemberNo
		,COUNT(*) AS dupeCount
	FROM Members
	GROUP BY MemberNo
	HAVING COUNT(*) > 1
	) HLM2 ON HLM1.MemberNo = HLM2.MemberNo
ORDER BY HLM1.MemberNo

Fourth

SELECT [id]
	,[Source]
	,[MemberNo]
	,[FirstName]
	,[MiddleName]
	,[LastName]
	,[Suffix]
	,[Email_1]
	,[Email_2]
	,[Email_3]
	,[ActiveMember]
	,ROW_Number() OVER (
		PARTITION BY [MemberNo]
		,[FirstName]
		,[MiddleName]
		,[LastName]
		,[Suffix]
		,[Email_1]
		,[Email_2] ORDER BY [MemberNo]
		) RowNumber
FROM [Members]
ORDER BY [MemberNo]
Originally Posted on February 28, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code MSSQL

Post navigation

Previous post
Next post

Related Posts

Unix Change Static IP

Posted on November 5, 2015December 29, 2015

It is best to do this on the machine itself and not remotely as you will lose connection. sudo cp /etc/network/interfaces /etc/network/interfaces.`date +"%m-%d-%Y_%I-%M-%S"` sudo sed -i ‘s|address 192.168.1.16|address 10.1.1.16|’ /etc/network/interfaces sudo sed -i ‘s|netmask 255.255.255.0|netmask 255.255.0.0|’ /etc/network/interfaces sudo sed -i ‘s|gateway 192.168.1.1|gateway 10.1.1.1|’ /etc/network/interfaces sudo service resolvconf restart sudo /etc/init.d/networking…

Read More

PowerShell – Backup Windows Drivers

Posted on March 18, 2020August 17, 2024

$DriverBackupPath = "$($env:USERNAME)\Downloads\DriverBackup\$($(Get-WmiObject -Class:Win32_ComputerSystem).Manufacturer)\$($(Get-WmiObject -Class:Win32_ComputerSystem).Model)" mkdir -p $DriverBackupPath -Force Export-WindowsDriver -Verbose -Destination $DriverBackupPath -Online Originally Posted on March 18, 2020Last Updated on August 17, 2024 All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system…

Read More

Mac OSX – DNSMasq Ad Block DNS

Posted on July 30, 2016October 21, 2016

# Get IP – Start ip=$(ipconfig getifaddr en0) nen=0 while [ -z $ip ]; do let nen=nen+1 eth="en$nen" #echo $eth ip=$(ipconfig getifaddr $(echo $eth)) done echo $ip # Get IP – Stop # Install Homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # Update your homebrew installation brew upgrade # Install dnsmasq…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes