Jump to content

DISTINCT help


patrickin

Recommended Posts

I am querying my DB to get some listings.  But because  a listing can fall into up to 5 sub categories, they can be returned up to 5 times by the following query, however I need duplicates removed, via DISTINCT.  However I cannot figure out how to place DISTINCT in this query, so that it actually works, as I am still getting duplicates.  Currently no errors are being thrown out, I'm just getting dupes, and I think my SQL ver and table structure is irrelevant for this question.

 

SELECT DISTINCT listings.*, categories.ID as catID, subcategories.ID as subID, subcategories.categoryID as sccatID FROM listings, categories, subcategories WHERE listings.active = 1 AND subcategories.categoryID = 1 AND categories.ID = 1 AND (listings.subcategory1ID = subcategories.ID OR listings.subcategory2ID = subcategories.ID OR listings.subcategory3ID = subcategories.ID OR listings.subcategory4ID = subcategories.ID OR listings.subcategory5ID = subcategories.ID

 

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/209475-distinct-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.