我有兩個表。SQL,如何在SQL中連接兩個具有名稱的ID
第一表 「玩家」 載:
Player_id;
Name;
Surname;
第二個表 「替換」 載:
Sub_id;
In_player_id;
Out_player_id;
,現在我想打印的in_player_id
姓名和sql
使用select
的out_player_id
語言
我有兩個表。SQL,如何在SQL中連接兩個具有名稱的ID
第一表 「玩家」 載:
Player_id;
Name;
Surname;
第二個表 「替換」 載:
Sub_id;
In_player_id;
Out_player_id;
,現在我想打印的in_player_id
姓名和sql
使用select
的out_player_id
語言
這可以使用兩個JOIN
s:
SELECT INPLAYER.Name, INPLAYER.Surname, OUTPLAYER.Name, OUTPLAYER.Surname
FROM Substitutions
INNER JOIN Player AS INPLAYER ON (Substitutions.In_player_id = INPLAYER.Player_id)
INNER JOIN Player AS OUTPLAYER ON (Substitutions.Out_player_id = OUTPLAYER.Player_id)
對於Oracle數據庫,刪除「AS」關鍵字。
它說「缺少kewords」在3行「AS」附近的東西 – szufi
@sgeddes作品在SQL服務器管理工作室2012年爲我罰款。你確定所有表和列的名稱和parantheses是正確的嗎? –
這是一個非常基本的'join',只需要對'player'表執行兩次。你有什麼嘗試? – sgeddes
[sql join two table]可能重複(http://stackoverflow.com/questions/9171963/sql-join-two-table) – Halfwarr