这是我在这里提出的问题的后续行动。使用相同类型的查询,如果存在“genre.name = 'Classic Movies' 和 'star.name = Humphrey Bogart' 之类的限制,我如何确保获得 10 部电影。” 需要明确的是,无论过滤限制是什么,查询都必须返回 10 部电影的数据。
SELECT movie.id, movie.title, star.name, star.name_url, dir.name,
dir.name_url, genre.name, genre.name_url
FROM
(SELECT * FROM movie WHERE movie.id > 0 ORDER BY movie.id LIMIT 10) movie
LEFT JOIN actor
ON (movie.id = actor.movie_id)
LEFT JOIN person AS star
ON (actor.person_id = star.id)
LEFT JOIN director
ON (movie.id = director.movie_id)
LEFT JOIN person AS dir
ON (director.person_id = dir.id)
LEFT JOIN genre_classification
ON (movie.id = genre_classification.movie_id)
LEFT JOIN genre
ON (genre_classification.genre_id = genre.id)