Closed Thread Icon

Topic awaiting preservation: MySQL/PHP finding duplicates in table Pages that link to <a href="https://ozoneasylum.com/backlink?for=27945" title="Pages that link to Topic awaiting preservation: MySQL/PHP finding duplicates in table" rel="nofollow" >Topic awaiting preservation: MySQL/PHP finding duplicates in table\

 
Author Thread
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 05-17-2006 14:44

Greets!

I'm looking for a way to find duplicates in a db table. Let's say I have a zillion records, and want to find any records with duplicate 'name'. How is this accomplished? I know I can do a "select * from myTable where name = 'blah'", but that's manually looking for specific records. I want to spit out all records where a field appears more than once. I hope that makes sense.

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 05-17-2006 15:04

Couldn't you use GROUP BY to accomplish this?

Use a COUNT to identify multiple occurances, and only use those where count > 1?

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-17-2006 18:30

Indeed, DL is on the right road.

You'll need to use having to select on the grouped columns though...
like

code:
select count (id) as cnt  from myTable GROUP by name HAVING cnt > 1



so long,

->Tyberius Prime

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 05-18-2006 01:10

Ah - that's cool. Much appreciated!

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 05-18-2006 02:23

Boy could I have used something like that about 2 months ago.

It sounds so simple when TP says it, but I sure didn't come up with that solution.

- Butcher -

divinechaos
Nervous Wreck (II) Inmate

From:
Insane since: Dec 2001

posted posted 05-18-2006 08:13

SELECT DISTINCT might also help compile an index of which rows you want to keep, though admittedly TP hit that nail pretty well already.

Just a thought,
DC

« BackwardsOnwards »

Show Forum Drop Down Menu