I need to select results from one table based on certain matching values in a couple of other tables. I have the following tables:
person: id, firstname, lastname
team: id, teamname
player: id, person_id(FK), team_id(FK)
coach: id, person_id(FK), team_id(FK)
I need to return all the coaches and players names for each team. I've only ever used inner joins, and it doesn't seem like I can use those here, so any idea how to do this?
This will give you the coach:
And this will give you the players:
So, the non-elegant, simple answer is to just toss it all together with
UNION
.Just use an OR in the join to Team
Or if you perfer if and your database has COALESCE