php - Left Joining three MySQL tables -


tbl_teams: team_id | team_name
tbl_players: player_id | player_fname | player_sname | player_bplace | player_bdate
tbl_players_stats: player_id | season_id | player_squad_no | team_id | player_apps | player_goals

sorry if basic question, mysql tables , columns above i'd join tables , display results season_id , team_id selected. need using php this:

player_squad_no | player_sname, player_fname | team_name | player_apps | player_goals

i've looked @ examples on here still can't figure out how write mysql query 3 separate tables , how specify table name before column name. i've seen examples initial. tt.teams instance. left join way it?

any appreciated. in advance.

with 3 separate tables, write join this:

select * table_a left join table_b b using(id) left join table_c c using(id) 

note using(column) syntactic alternative on a.column = b.column can use when columns want join on have same name in both tables.

in above example, tables aliased as can refer them alias instead of full table name. (as optional; can give alias after table, if you're paying character.) try choose alias makes sense when @ it; times people alias this:

select a.name, b.state customers left join orders b ...etc. 

but if have longer query, how supposed remember tables a , b refer to? @ least, make sense alias customers c , orders o; in cases, go step further: registration reg, instance. gets more , more important join more , more tables together.

here's 1 way write query:

select     stats.player_squad_no,     concat_ws(', ', players.player_sname, players.player_fname) player_full_name,     teams.team_name,     stats.player_apps,     stats.player_goals tbl_players players left join tbl_players_stats stats using(player_id) left join tbl_teams teams using(team_id) 

the concat_ws() function included assemble player's full name way indicated wanted displayed. since function output column messy name, gave alias.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -