Jump to content

[SOLVED] Getting a few duplicates in an INNER JOIN query


Recommended Posts

I apologize in advance for the largeness of this query.

 

I'm using mysql 5.0.67.

 

My problem is that the query below returns duplicate results for the same item if it appears in more than one category.

 

For example I might have product AB-23423 that shows up in categories 16 and 103. With the query below, I unfortunately pull out two copies of that product even though I only want one.

 

SELECT sh_products.id AS id , sh_prod_categories.cat_id AS catid , sh_products.prod_id AS prod_id , sh_products.prod_name AS prod_name , sh_products.prod_vendor AS prod_vendor , sh_products.prod_thumb AS prod_thumb , sh_products.prod_price AS prod_price , sh_categories.cat_title AS category FROM sh_products 
INNER JOIN sh_prod_categories on sh_products.prod_id = sh_prod_categories.prod_id
INNER JOIN sh_categories on sh_prod_categories.cat_id = sh_categories.cat_id 
WHERE sh_categories.cat_id = 17 
OR sh_categories.cat_id = 216 
OR sh_categories.cat_id = 16 
OR sh_categories.cat_id = 18 
OR sh_categories.cat_id = 103 
ORDER BY REPLACE(REPLACE(prod_name,'"',''),'\'','') DESC 

 

Given that this statement is on the very edge of my abilities already, can someone suggest a tweak that would result in only one result, even when a product appears in two categories?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.