Getting duplicates returned from db

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Getting duplicates returned from db

Post by Luke »

I am making a new directory and I now have 3 tables set up...

directory - contains all info relating to the company listed
cat - contains all available categories
dircat - contains information relating the two above tables to eachother

Now I've created this query to select only categories that have one or more listings in them, but it returns duplicates of the same category (because there are more than one listing with that category) How would I make mysql not return duplicates of the same category?

Code: Select all

SELECT cat.cat_id, cat.cat_category
FROM cat, dircat
WHERE cat.cat_id = dircat.cat_id
If there is no way to make mysql return this... is there a convenient php function that will find all duplicate values and delete them from the return array?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

group by category
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

huh?
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

Post Reply