Solved

SQL - How to count duplicate record

Posted on 2012-03-30
4
234 Views
Last Modified: 2012-04-16
I have a table with firstName, lastName and other fields,  I will like to count all the rows have the same firstName and lastName.
0
Comment
Question by:tommym121
4 Comments
 
LVL 17

Expert Comment

by:Anuroopsundd
ID: 37789785
SELECT firstname, lastname, COUNT(*)  FROM person  GROUP BY firstname, lastname  HAVING COUNT(*) > 1;
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37792066
Something like this perhaps:
SELECT COUNT(DISTINCT firsname + lastname)
FROM YourTable
0
 
LVL 15

Accepted Solution

by:
deepakChauhan earned 500 total points
ID: 37793908
try these hope so you will be got your result

 select a.firstname, a.lastname from table_A as a
 join Table_A as b on a.firstname=b.fistname and a.lastname=b.lastname

or

select firstname, lastname from (
select row_number() over( partition by firstname, lastname order by firstname) as row,
firstname, lastname from aaa) a where row >1

or
select count(*) from (
select row_number() over( partition by firstname, lastname order by firstname) as row,
firstname, lastname from aaa) a where row >1
0
 

Author Closing Comment

by:tommym121
ID: 37852953
Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question