Thanks for the reply Rudy.
I changed it a little to return the right results:
PHP Code:
SELECT
p2.*
, b2.name AS related_brand
FROM QS_products AS p
INNER
JOIN QS_brands AS b
ON b.id = p.brand_id
LEFT OUTER
JOIN QS_products_related AS r
ON r.product_id = p.id
LEFT OUTER
JOIN QS_products AS p2
ON p2.id = r.related_id
AND p2.visible = 'yes'
LEFT OUTER
JOIN QS_brands AS b2
ON b2.id = p2.brand_id
WHERE p.id = 1
AND p.visible = 'yes'
Note the p2.* is for brevity's sake.
Looks quite laborious though? I'd be interested in a better solution if you have any opinions for one.
The other option I had for this was a 'related' field in the products table with a csv line of id's (2,3,4,5,6), the query being:
PHP Code:
select p.*, `b`.`name` as brand_name
from QS_products p
JOIN `QS_brands` b ON `p`.`brand_id` = `b`.`id`
where p.id in (2,3,4,5,6) and p.visible = "yes";
The 2,3,4,5,6 being a variables value. From searching here you seem to not recommend the IN() approach however?