Exercises
Objectives
This lesson introduces no new concepts. It’s a chance to practice everything from this module: SQL syntax, keywords, identifiers, comments, literals, expressions, SELECT, DISTINCT, and aliases.
All exercises are runnable against the products table set up earlier in this module.
Exercises
-
Write a query that selects every column from
products. -
Write a query that selects only
product_nameandin_stock. -
Write a query that returns every distinct
categoryinproducts. -
Write a query that selects
product_nameandprice, aliased tonameandunit_price. -
Write a query with an expression that calculates each product’s price with 8% sales tax added (
price * 1.08), aliased toprice_with_tax. -
Add a single-line comment above your query from exercise 5 explaining what it calculates.
-
Write a query selecting the literals
'sample',100, andfalse, each with your own alias. -
Explain, in your own words, why
SELECT DISTINCT category FROM products;returns 3 rows whileSELECT category FROM products;returns 10.
Recap
You can now read and write a basic SQL statement, tell keywords from identifiers, use comments and literals correctly, write a simple expression, and control exactly what a query returns and what it’s labeled. That’s the foundation every later module’s SQL builds on.
Next module: Creating Tables, where you’ll learn to build the kind of table this module only gave you, starting with CREATE TABLE itself.