PDF Version Available
This document is also available in PDF format: week3.pdf
The PDF version includes bookmarks for easy navigation and is optimized for printing.
Accessibility Notice
This document is also available in HTML format at:
Link: https://aholdengouveia.name/AdvData/labs/week3.html
The HTML version provides enhanced accessibility features including keyboard navigation, screen reader support, responsive design, dark mode support, and high contrast options.
Request
Request: DATA-5809
Requested by: Inventory lead
Data: Your database from the SQL Review lab
Background
Your manager liked your first queries. Now the inventory lead wants to combine your data with a second table, and to know whether anything in the data doesn't match up. Rows that don't match are a common sign of data problems, and finding them early saves the company time and money. You'll start with join training, then apply it to your own data.
Learning Outcomes
By the end of this lab, you will be able to:
- Write SQL queries that join two tables
- Create a lookup table, and explain how it relates to your data using primary and foreign keys
- Choose between an inner join and a left join, and explain how the results differ
- Use a join to find data quality problems, such as rows with no match
Lab Instructions
Screenshots
Several parts of this lab ask for a screenshot. Each screenshot should have your name, term, and year. One of the easiest ways to do that is make a text document with your name and term/year on your computer and save it to use all term. Any screenshots that don't include this information won't be counted.
Part 1: SQL Joins Tutorial
Go through these 3 sections of SQLBolt (linked under Resources), and complete the exercises at the end of each one:
- SQL Lesson 6: Multi-table queries with JOINs
- SQL Lesson 7: OUTER JOINs
- SQL Lesson 8: A short note on NULLs
Take a screenshot of each section after you complete its exercises. Make sure you have the green checkmark on each problem.
Part 2: Join Challenges
Complete 3 HackerRank challenges that use joins (linked under Resources). You can filter the list by basic and advanced joins. HackerRank is free, but you need to register so your work is saved to your profile.
- Take a screenshot of each solution.
- With each screenshot, explain how you solved it and what resources you used. If you needed a hint, say where you found it.
- Pick one of your 3 solutions and explain which type of join you used and why. What would change in the results if you used the other type (inner instead of left, or left instead of inner)?
- Take a screenshot of your HackerRank profile showing the completed challenges.
Optional, not required for this class: if you'd like more practice, try more of the HackerRank join challenges.
Part 3: Joins on Your Data
Your data set from the SQL Review lab is one table, so you'll make a second table to join it to. Books are my example data only, so use your own data set.
- Create a small lookup table with 5 to 10 rows that adds information about one column in your main table. For example, my book data has a format column, so I made a table that matches each format to the shelf section where it goes in the store.
- Explain how the two tables relate. Which column links them? What is the primary key of your lookup table, and which column in your main table acts as the foreign key?
- Write 3 queries that join your two tables, documented in the same format as the SQL Review lab. Use at least one inner join and at least one left join.
- Make one of your 3 queries a data quality check: use a left join to find rows in your main table that have no match in your lookup table. In the Notes, explain why those rows don't match and what you would do about it.
- Take a screenshot of each query and its results.
Acceptance Criteria
This request is done when:
- All 3 SQLBolt sections are complete, with a green checkmark on every problem
- 3 HackerRank join challenges are solved, each with an explanation, and your profile shows them complete
- Your lookup table has 5 to 10 rows and a primary key, and you've explained how it links to your main table
- 3 join queries documented in the sample format, with at least one inner join and one left join
- One query is a data quality check, with notes explaining the rows that don't match and what to do about them
- Every screenshot follows the screenshot rules
Deliverables
One file that includes:
- Part 1: your 3 SQLBolt screenshots
- Part 2: your 3 HackerRank screenshots with explanations, your answer about join types, and your profile screenshot
- Part 3: the commands you used to create your lookup table, your explanation of how the tables relate, and your 3 documented queries with a screenshot of each one and its results
Audience: the inventory lead and the rest of the data team.
Resources
References, a video, a PowerPoint and some notes are available at my website Link: https://www.aholdengouveia.name/AdvData/sqlpt2.html
SQLBolt, the tutorial for Part 1 Link: https://sqlbolt.com/
HackerRank join challenges for Part 2 Link: https://www.hackerrank.com/domains/sql?filters%5Bsubdomains%5D%5B%5D=join&filters%5Bsubdomains%5D%5B%5D=advanced-join
Sample query documentation, with join examples (Q3 and Q4) Link: https://www.aholdengouveia.name/AdvData/labs/SampleQueryDocumentation.txt