我需要从2个表中将数据附加到Access中的现有表

时间:2013-05-18 01:54:44

标签: sql ms-access

我有两个表中的数据:

tbl_games包含以下列:

game_id, season, date, home_team, visiting_team, 
home_score, visiting score, home_score_half_time, visiting score_half_time

tbl_formation包含以下列:

game_id, home_formation, home_team, visiting_team, visiting_formation

我想将这些表中的数据附加到具有以下列的game_team表中:

game_id, team_id, status, end_score, half_score, Formation

而不是将home_team visiting_team分开,我希望将它们全部置于team_id之下,状态表明它是主队还是特定比赛的客队。

我正在尝试下面的查询,但它不起作用

INSERT INTO Game_Team ( game_id, Team_ID, End_Score, half_score, Formation )
SELECT G.game_id, G.home_team, G.home_score_half_time, G.home_score, GL.home_formation
FROM tbl_games AS G 
INNER JOIN tbl_formation AS GL ON G.game_id = GL.game_id;

2 个答案:

答案 0 :(得分:0)

INSERT INTO Game_Team ( game_id, Team_ID, End_Score, half_score, Formation )
values(SELECT G.game_id, G.home_team, G.home_score_half_time, G.home_score, GL.home_formation
FROM tbl_games AS G 
INNER JOIN tbl_formation AS GL ON G.game_id = GL.game_id);

我添加了值。 见insert data from one table to another in mysql

答案 1 :(得分:0)

试试这个

INSERT INTO Game_Team ( game_id, Team_ID, End_Score, half_score, Formation )
SELECT G.game_id, G.home_team & ' ' & G.visiting_team, G.home_score_half_time, G.home_score, GL.home_formation
FROM tbl_games AS G 
INNER JOIN tbl_formation AS GL ON G.game_id = GL.game_id;