i\'m making an e-store, so i have 3 tables:
1) goods
id | title
--------+-----------
1 | Toy car
2 | Toy pony
3 | Do
When you want to show the goods with goods id = 2
SELECT DISTINCT
goods.*
FROM
goods
LEFT JOIN links ON links.goods_id = goods.id
WHERE links.tag_id IN (SELECT links.tag_id
FROM links
WHERE links.goods_id = 2)
when you did not include goods_id = 2
SELECT DISTINCT
goods.*
FROM
goods
LEFT JOIN links ON links.goods_id = goods.id
WHERE links.goods_id != 2 AND links.tag_id IN (SELECT links.tag_id
FROM links
WHERE links.goods_id = 2)
can see on http://sqlfiddle.com/#!2/0fb60/38