我想检索数据表格3指定表格
这样当用户输入特定的Movie_id时,Userid Fname Lname将形成来自Movies的用户详细MovieName 这是我试过的
SELECT UserDetail.FName
FROM
UserDetail UserDetail
INNER JOIN
UserLikedMovies UserLikedMovies
ON
UserDetail.User_id = UserLikedMovies.User_id
INNER JOIN
(
SELECT
Movies.MovieName,
Movies.Movie_id
FROM
Movies Movies
INNER JOIN
UserLikedMovies UserLikedMovies
ON
Movies.Movie_id = UserLikedMovies.Movie_id
INNER JOIN
UserDetail UserDetail
ON
UserLikedMovies.User_id = UserDetail.User_id
WHERE
Movies.Movie_id IN ( Select UserLikedMovies.Movie_id from UserLikedMovies where UserLikedMovies.Movie_id = 4)
) as ABC
ON UserLikedMovies.Movie_id = ABC.Movie_id
AND Movies.Movie_id = ABC.Movie_id
答案 0 :(得分:0)
这是非常简单的查询:
SELECT ud.`User_id`, ud.`Fname`, ud.`Lname`, m.`MovieName`
FROM `Movies` m
RIGHT JOIN `UserLikedMovies` ulm ON ulm.`Movie_id` = m.`Movie_id`
LEFT JOIN `UserDetail` ud ON ud.`User_id` = ulm.`User_id`
WHERE m.`Movie_id` = 4
我不知道你为什么使用可怕的子查询来完成这个简单的任务。
答案 1 :(得分:0)
假设movie_id为9,则查询在下面。
SELECT User.Fname,User.Lname,(SELECT MovieName FROM Movies WHERE Movie_id = 9)AS MovieName 来自UserDetail用户 INNER JOIN UserLikedMovies赞 ON User.User_id = Like.User_id 在哪里.Movie_id = 9;