From the course: SQL for Non-Programmers
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Solution: Equijoins solved - SQL Tutorial
From the course: SQL for Non-Programmers
Solution: Equijoins solved
- How did you use an equi-join to solve this multi-table SQL challenge? You are tasked with pulling an olive oil product sales report split by region, requiring a combination of two tables. These tables can be matched based on equality, so an equi-join would look like this. We'll start out by selecting the columns we need. SELECT r.region, go to the next line, SUM(s.order_total) AS total_sales. I'm using aliases r and s, which I'll assign to the tables I'm pulling from. Then we are going to specify the tables we want to query from. Going to the next line, in the FROM clause, I'm going to place regions AS r, sales AS s. Make sure to always separate the tables here with a comma and assign their aliases. Then we need to join the tables on their common key using a WHERE clause. What is the common key or unique identifier that both tables share? It's state, so we'll add that onto the next line. WHERE r.state = s.cust_state. We also need to add a filter here for only the olive oil product…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.