2013-05-18 33 views
0
追加到現有的表

我有兩個表中的數據:我需要的數據在Access從2個表

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_teamvisiting_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; 
+0

,如果你想看到的數據,那麼你爲什麼要使用INSERT INTO? –

+1

它怎麼沒用?任何錯誤?請張貼他們。不是期望的結果? –

回答

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

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; 
+0

當我運行它時,我得到一個未定義的函數CONCAT錯誤 –

+0

我已經修復了我的查詢 – dArc

+0

我仍然在select語句中得到語法錯誤 –