oracle - SQL JOIN and LEFT OUTER JOIN -
oracle - SQL JOIN and LEFT OUTER JOIN -
i've been having problem understanding example, have reply i'm having problem wrapping head around how works. how joins working exactly?
examine structures of player , 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 example, team managers players, , manager_id
column references player_id
column. players managers, manager_id
null
.
which select
statement provide list of players, including player's name, team name, , player's manager's name?
answer:
select p.last_name, p.first_name, m.last_name, m.first_name, t.team_name player p left outer bring together player m on (p.manager_id = m.player_id) left outer bring together team t on (p.team_id = t.team_id);
so first left outer join
takes player table, adds on info each players manager. each player has id
manager, player id
. if mr. a, player_id 9
, manager ted, player_id 5
, ted's manager_id 9
. first bring together takes ted's manager_id
, 9
, , matches player_id
of manager, mr. a, manager's info on table well, , m.last_name
, m.first_name
show mr. a's name. sec bring together takes team_id
, matches table of teams, appending team_name
player's info in table.
it's tough explain without sample info , diagrams. sorry.
sql oracle join outer-join
Comments
Post a Comment