Module 1 Lab: Basic Queries
Congratulations! You’ve made it to the end of Module 1. You’ve learned how to retrieve data, filter it, sort it, handle missing values, and limit your results.
This lab is a capstone exercise for the module. It requires you to combine multiple clauses into a single, cohesive query.
The Scenario
Our E-Commerce store has an expansive products table. The marketing team is launching a “Premium Tech” newsletter, and they need a very specific list of items from the database to feature in their email template.
They have provided the following requirements:
- They only want to see the
nameand thepriceof the product. - The product must be in the
'Electronics'category. - The product must be considered “premium,” which means the
priceis $1,000 or greater (inclusive). - The items must be sorted from most expensive to least expensive.
- They only have room for the top 3 items in the newsletter layout.
Building the Query
Remember the golden rule of SQL clause ordering:
SELECT(What columns do you want?)FROM(Which table?)WHERE(What are the conditions?)ORDER BY(How should it be sorted?)LIMIT(How many rows?)
[!TIP] If you get stuck, try building the query one step at a time. First, just
SELECT *to see the table. Then add theWHEREclause. Then restrict the columns. Finally, add the sorting and limits.
Use the terminal on the right to construct your query and help the marketing team launch their campaign! Once you complete this, you will be ready to tackle Module 2: Aggregation!