Skip to content
Advertisement

SQL Query joins tables and returns all records with dynamic id

I have two tables: staffs and teams. Here are their properties:

I want to write a query that returns all the staff id’s records who are supervisors. I know how to join the table but then I don’t know how to finish out the query. I also do not want duplicates.

In the above example data: the staff ids for “john”, “bob” and “alex” should all be returned once. The staff id for “george” should not be returned because he is not a supervisor.

Advertisement

Answer

Would be easier to do with a subquery in the where clause

EDIT: SQL Fiddle

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement