基于系列作品选择相似电影

huangapple go评论55阅读模式
英文:

Select similar movies based on franchises

问题

以下是您要的翻译部分:

"这个查询有效,但我只是想知道这是否是正确的做法:

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"

英文:

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

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

答案1

得分: 0

以下是翻译好的部分:

您当前的查询是正确的,但您也可以使用联接来表示这个查询:

<!-- language: sql -->

    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;
英文:

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

<!-- language: sql -->

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 &lt;&gt; 23;

huangapple
  • 本文由 发表于 2023年2月26日 21:24:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572287.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定