I've been having trouble understanding this example, I have the answer but I'm having trouble wrapping my head around how this works. How are the joins working exactly?
Examine the structures of the PLAYER and TEAM tables:
PLAYER
-------------
PLAYER_ID NUMBER(9) PK
LAST_NAME VARCHAR2(25)
FIRST_NAME VARCHAR2(25)
TEAM_ID NUMBER
MANAGER_ID NUMBER(9)
TEAM
----------
TEAM_ID NUMBER PK
TEAM_NAME VARCHAR2(30)
For this example, team managers are also players, and the MANAGER_ID
column references the PLAYER_ID
column. For players who are managers, MANAGER_ID
is NULL
.
Which SELECT
statement will provide a list of all players, including the player's name, the team name, and the player's manager's name?
ANSWER:
SELECT p.last_name, p.first_name, m.last_name, m.first_name, t.team_name
FROM player p
LEFT OUTER JOIN player m ON (p.manager_id = m.player_id)
LEFT OUTER JOIN team t ON (p.team_id = t.team_id);