search for row duplicates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rafaell
Forum Newbie
Posts: 4
Joined: Sun Apr 04, 2010 12:45 pm

search for row duplicates

Post by rafaell »

I have a database where in 2 columns some of the information is repetitive.
Ex:
col1, col2
1,2
2,4
1,3
1,2
1,2
2,5
2,4

And I want to search the rows and just pull out the unique ones, leaving out the duplicates.
So in the above example, I'd be left with:
1,2
2,4
1,3
2,5

I'm guessing an array, but can't figure out the comparison part to see which one is unique.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: search for row duplicates

Post by requinix »

Use DISTINCT.

Code: Select all

SELECT DISTINCT * FROM `table`
Post Reply