Solved

SQL - How to count duplicate record

Posted on 2012-03-30
4
232 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now