I have a MySQL question, I'm wondering if the answers lies in using joins. I apologize in advance if the title is confusing or misleading.
I have 2 tables: Teams, Contractors
TEAMS
|team_id | location|
--------------------
| 1 | space1 |
--------------------
| 2 | space2 |
--------------------
| 3 | space3 |
--------------------
CONTRACTORS
|cont_id | location| team_id|
-----------------------------
| 1 | space1 | 1 |
-----------------------------
| 2 | space1 | 0 |
-----------------------------
| 3 | space3 | 3 |
-----------------------------
| 4 | space3 | 3 |
-----------------------------
| 5 | space3 | 0 |
-----------------------------
I would like to create a query that finds all the contractors that are at a specific location. The issue is, I only know the team_id. (team_id = 0 in the CONTRACTORS table means the contractor is not currently part of a team).
For example, I'm given the team_id = 3. The team with team_id = 3 is located at space3. I want to find all the contractors that are located at space3 (cont_id = 3, 4, 5 in this example).
Is there a way to achieve this with a single MySQL query? Or do I need to perform a query to get the location of the team, and then a 2nd query to find all contractors at that location?