MISSION 373

Building and Organizing Complex Queries

In the third lesson of this SQL Intermediate course, you'll focus on how to build and organize more complex queries to increase your knowledge of SQL and add more tools to your toolbox. You’ll also learn more about formatting and SQL best practices so that you can make your queries more readable for others (or for yourself in the future).

You'll learn about the `WITH` clause to create CTEs along with `CREATE VIEW` to organize your queries. You will also learn how to use set operations such as `UNION`, `UNION ALL`, `INTERSECT`, and `EXCEPT` to combine results from two tables that have no column relation. 

Of course, you’ll get hands-on practice using and applying each of these concepts, as well as practicing the SQL concepts you’ve learned in previous lessons.

To facilitate your building and organizing complex queries, you'll be working with the Chinook database, a music collection database that includes song details like track name, album name, artist name, genre, and the number of tracks purchased.

Objectives

  • Learn to format queries to make them readable.
  • Learn how use the WITH clause and views to organize your queries.
  • Learn how to use set operations to combine tables.

Mission Outline

1. Introduction
2. Writing Readable Queries
3. The With Clause
4. Creating Views
5. Combining Rows With Union
6. Combining Rows Using Intersect and Except
7. Multiple Named Subqueries
8. Challenge: Each Country's Best Customer
9. Next Steps
10. Takeaways

sql-joins-relations

Course Info:

Intermediate

The median completion time for this course is 4 hours.​View Details​​​

This course requires a basic subscription and has four mission including two guided projects. It is the 6th course in the Data Analyst in R path.

START LEARNING FREE

Take a Look Inside