Solved

SQL - How to count duplicate record

Posted on 2012-03-30
4
237 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:
Deepak Chauhan 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

Title # Comments Views Activity
Sql Server group by 10 45
Need help with a Stored Proc on Sql Server 2012 4 28
TSQL recursive CTE challenge... 8 29
Disable TLS1.0 on Win 2012 server 7 30
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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