
Merging Data with LEFT JOIN - Exercises
1. The roles of actors
We have data of actors (table actors). And data of roles (table roles).

We now want to know which actor fulfills which roles.
For this, we will use LEFT JOIN.
Complete the query below to merge the tables.
- Left table:
actors. - Right table:
roles. - Column
idfrom tableactorsmatches with columnactor_idfrom tableroles. - Use
LEFT JOINandON. - Select all columns.
2. Use aliases
In the previous exercise, we wrote out the table names in full.
We will now use aliases with AS.
Reuse your code from the previous exercise and apply aliases.
- Name table
actors:a. - Name table
roles:r.
3. Make a specific selection
So far, we have selected all columns.
We will now make a specific selection.
Reuse your code from the previous exercise and make a specific selection.
- Select all columns from table
actors. - Select only column
rolefrom tableroles.
4. (Extra) Grouping
We now have a table with all the roles of actors.
By grouping, we will determine how many roles an actor has played.
- Table
actorsalready contains a columnfilm_count. - But maybe an actor plays multiple roles in one film.
Reuse your previous code and write a query.
- Use
GROUP BY. - Group by column
idfrom tableactors. - Count the number of roles with function
COUNT(). - Select the following columns:
first_name.last_name.COUNT(...).
5. (Extra) Filtering and sorting
We now have a table with the number of roles of actors.
By filtering and sorting, we will make the result more useful.
Reuse your previous code and write a query.
Such that:
* Filter so that only actors with more than 1 role appear.
* Use HAVING.
* Sort descending by the number of roles.
* Use ORDER BY.