Mysql 查询内部连接


Mysql query inner 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";

你把FROM cm_matches放在INNER JOIN之后,这应该在INNER 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

在 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";

尝试:

$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";

您的查询应该是这样的:

$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";