Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select similar movies based on franchises

Let’s say i have this table

id movie_id franchise_id
1 23 15
1 24 15
1 25 15
1 26 16
1 23 16

One movie can have multiple franchises, so i need to get all movies with the same franchises. Like if i want to get all similar movies for the movie with id 23, i should get 24 25 26.

This query works, but i’m just wondering if this is the right way of doing it

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT DISTINCT movie_id FROM movies_franchises WHERE franchise_id IN (SELECT franchise_id FROM movies_franchises WHERE movie_id = 23) AND movie_id != 23

>Solution :

Your current query is fine, but you could also express this using a join:

SELECT m2.movie_id
FROM movies_franchises m1
INNER JOIN movies_franchises m2
    ON m2.franchise_id = m1.franchise_id
WHERE m1.movie_id = 23 AND m2.movie_id <> 23;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading