I have three tables like these:
Thus, each movie has its own set of tags. I need to get similar movies based on a set of tags. I want to say that 10 films are sorted by the number of matching tags.
If I create a view as shown below, it makes MySQL leave. There are 30k + entries in the "tag" and "tagged" tables.
create view relatedtags as
select
entityLeft.id as id,
entityRight.id as rightId,
count(rightTagged.id) as matches
from
entity as entityLeft join tagged as leftTagged on leftTagged.entity = entityLeft.id,
entity as entityRight join tagged as rightTagged on rightTagged.entity = entityRight.id
where leftTagged.tag = rightTagged.tag
and entityLeft.id != entityRight.id
group by entityLeft.id, entityRight.id
source
share