Solved

SQL - How to count duplicate record

Posted on 2012-03-30
4
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Disable TLS1.0 on Win 2012 server 7 117
sql 2016 data tools breakdown.. 1 36
SQL Database Restore 2008 R2 1 43
Checking for column changes SQL 2014 4 42
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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