I have a normalized table:
`Table: TheMovies` id | MovieName --------------------- 1 | Zootopia 2 | Moana 3 | Toy Story `Table: TheGenres` id | GenreName --------------------- 21 | Action 22 | Animation 23 | Adventure `Table: mMoviesGenres` movieID | genreID --------------------- 1 | 21 1 | 23 2 | 22 2 | 21 3 | 23 3 | 21
Everything works fine, but I need a query that will show me similar films in the same genres (in our case, we need similar films for MovieID = 1, which should output MovieID = 3 as the result).
Can you give me an SQL query so that I have a basic idea to do this in order to be able to create more complex queries?
So far my request is:
SELECT TheMovies.* FROM mMoviesGenres JOIN TheMovies ON mMoviesGenres.movieID = TheMovies.id WHERE mMoviesGenres.genreID IN ( SELECT genreID FROM mMoviesGenres WHERE movieID = 1 )
** In my opinion, Table: TheMovies do not need to do what I ask
Coder source share