I am creating a Tennis Ladder VIEW using MySQL and wish to do the following:
- Properly create a view that includes: All player's names
- These player names will come from the table: User - using the field: name
Here is a very simple structure of the database
...and here is the view query I have so far (query generated from HeidiSQL):
select `lm`.`id` AS `id`,
`l`.`ladderName` AS `ladderName`,
`l`.`ladderType` AS `ladderType`,
`l`.`manager_id` AS `manager_id`,
`lm`.`match_round` AS `match_round`,
`lm`.`match_court_scheduled` AS `match_court_scheduled`,
`lm`.`match_datetime_scheduled` AS `match_datetime_scheduled`,
`lm`.`match_date_completed` AS `match_date_completed`,
`lm`.`match_winner` AS `match_winner`,
`lm`.`team1_user1_id` AS `team1_user1_id`,
`lm`.`team2_user1_id` AS `team2_user1_id`
from (((`ladder_matches` `lm`
left join `ladder` `l` on((`lm`.`ladder_id` = `l`.`id`)))
left join `ladder_users` `lu` on((`lm`.`team1_user1_id` = `lu`.`id`)))
left join `users` `u` on((`lu`.`user_id` = `u`.`id`)))
order by `lm`.`id`