If I understand correctly, you want all tags for products that have a tag matching tags.tagid = '6000008'
. Logically, you can get this as:
SELECT tags.tagname, tags.tagid, tags.tagvalue, accessories.*
FROM accessories left join
tags
ON tags.product_id = accessories.product_id
WHERE accessories.product_id in (select product_id
from tags
where tags.tagid = '6000008'
)
Earlier versions of MySQL had performance problems with in
and subqueries. You can rewrite this as a join
:
SELECT tags.tagname, tags.tagid, tags.tagvalue, accessories.*
FROM accessories left join
tags
ON tags.product_id = accessories.product_id join
(select distinct product_id
from tags
where tags.tagid = '6000008'
) Filter
on accesories.Product_id = Filter.Product_id