Re: Finding Duplicate Numbers?

From: Date: Tue, 17 Apr 2001 18:30:07 +0000
Subject: Re: Finding Duplicate Numbers?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49019@lists.php.net to get a copy of this message
On Tuesday, April 17, 2001, at 11:00 AM, Devin Atencio wrote:
I have a SQL Table that has over 1,000 records and I was wanting to write a script that would find duplicate phone numbers and then list the duplicate phone numbers. I have been trying to think on how to do this but I can't think of a way. Can someone please help me on some code I could write to do this?
I think you want something like this (MySQL syntax, YMMV): SELECT phone_number, count(*) AS instances FROM my_table GROUP by phone_number HAVING instances >= 2 ORDER BY instances DESC This give you a list of all duplicated phone numbers, the number of times they appear in the table, and sorts them with the most-duplicated numbers first. To list them, you just need to loop through the result set echoing the phone number. Cheers, colin -------------------------------------- Colin Putney Whistler.com

« previous php.general (#49019) next »