Mysql查询内连接?

时间:2013-07-23 08:24:06

标签: php mysql sql join

这个查询有什么问题?它说:在“INNER JOIN cm_competitions ON cm_matches.competition_id = cm_competitions.compet附近使用的语法 这有什么不对?

$query_matches = "SELECT cm_matches.match_id, cm_competitions.name 
                   INNER JOIN cm_competitions.name 
                   ON cm_matches.competition_id = cm_competitions.competition_id 
                    FROM cm_matches 
                    WHERE cm_matches.club_h_id = 8 
                   OR cm_matches.club_v_id = 8";

4 个答案:

答案 0 :(得分:0)

您在FROM cm_matches之后放置INNER JOININNER JOIN之前应该SELECT cm_matches.match_id, cm_competitions.name FROM cm_matches INNER JOIN cm_competitions ON cm_matches.competition_id = cm_competitions.competition_id WHERE cm_matches.club_h_id = 8 OR cm_matches.club_v_id = 8 。所以试试这个查询:

{{1}}

答案 1 :(得分:0)

FROM 标记后使用 INNER JOIN

$query_matches = "SELECT cm_matches.match_id, cm_competitions.name  
                  FROM cm_matches 
                  INNER JOIN cm_competitions 
                  ON cm_matches.competition_id = cm_competitions.competition_id
                  WHERE cm_matches.club_h_id = 8 
                  OR cm_matches.club_v_id = 8";

答案 2 :(得分:-1)

尝试:

$query_matches = "SELECT cm_matches.match_id, cm_competitions.name FROM cm_matches INNER JOIN cm_competitions ON cm_matches.competition_id = cm_competitions.competition_id  WHERE cm_matches.club_h_id = 8 OR cm_matches.club_v_id = 8";

答案 3 :(得分:-2)

您的查询应该是这样的:

$query_matches = "SELECT cm_matches.match_id, cm_competitions.name FROM cm_matches INNER JOIN cm_competitions ON cm_matches.competition_id = cm_competitions.competition_id WHERE cm_matches.club_h_id = 8 OR cm_matches.club_v_id = 8";