i\'m making an e-store, so i have 3 tables:
1) goods
id | title
--------+-----------
1 | Toy car
2 | Toy pony
3 | Do
Some help:
Assuming you are looking the most similar to goods#1
SELECT a.*
FROM (SELECT * FROM goods WHERE id <> 1) a
LEFT JOIN (SELECT z.goods_id, count(*) as total
FROM links z
WHERE z.goods_id <> 1 AND
z.tag_id in (SELECT DISTINCT tag_id from links where goods_id = 1)
GROUP BY z.goods_id) b
ON a.id = b.goods_id
ORDER by b.total DESC
However, I think you can try something a bit different. Instead of ordering by the number of common tags, you can sort by the ratio of common tags. With this you will avoid the fact that the products with more tags will appear always at the top of the rankings, even if the relative common tags are not many.