内连接查询返回多行?

时间:2016-05-06 09:16:51

标签: mysql

我不知道下面的查询有什么问题。它返回12行而不是单行。请建议我下面的查询是否正确。如果没有,请更正以下查询中的问题。提前谢谢。

SELECT 
    M.name, MR. review, MAN.running_time, MC.screen_name, MI.producer, 
    MI.director,MI.story, MI.bgm_score,MI.screenplay, MI.music,
    MS.story, MS.screenplay, MS.dialogue, MS.direction, MS.music, MS.bgm, 
    MS.cinematography, MS.characterization, MS.shotlocation, MS.editing, 
    MS.production, MS.performance, CC.certificate FROM tttbl_review_language RL 
JOIN tttbl_censor_certificate CC 
JOIN tttbl_movie M
INNER JOIN tttbl_movie_review MR ON MR.movie_id=M.id
INNER JOIN tttbl_movie_analytics MAN ON MAN.movie_id=M.id
INNER JOIN tttbl_movie_cast MC ON MC.movie_id=M.id 
INNER JOIN tttbl_movie_info MI ON MI.censor_id=CC.id AND MI.movie_id=M.id
INNER JOIN tttbl_movie_score MS ON MS.movie_id=M.id 

WHERE M.id=1

1 个答案:

答案 0 :(得分:2)

on condition之间没有tttbl_review_language RL, tttbl_censor_certificate CC and tttbl_movie M 然后这些表可以生成其他结果的笛卡尔积。

    select 
    M.name, 
    MR. review, 
    MAN.running_time, 
    MC.screen_name, 
    MI.producer, 
    MI.director,
    MI.story, 
    MI.bgm_score,
    MI.screenplay, 
    MI.music,
    MS.story, 
    MS.screenplay, 
    MS.dialogue, 
    MS.direction, 
    MS.music, 
    MS.bgm, 
    MS.cinematography, 
    MS.characterization, 
    MS.shotlocation, 
    MS.editing, 
    MS.production, 
    MS.performance, 
    CC.certificate 
    FROM tttbl_review_language RL 
    JOIN tttbl_censor_certificate CC 
    JOIN tttbl_movie M  
    INNER JOIN tttbl_movie_review MR ON MR.movie_id=M.id  
    INNER JOIN tttbl_movie_analytics MAN  ON MAN.movie_id=M.id 
    INNER JOIN tttbl_movie_cast MC ON MC.movie_id=M.id 
    INNER JOIN tttbl_movie_info MI ON MI.censor_id=CC.id AND MI.movie_id=M.i