Chapter 1 · SELECT Basics
SQL SELECT Practice
Every SQL query starts with SELECT. It tells the database which columns you want back, and FROM tells it which table to read. Getting comfortable here makes every later topic easier.
These exercises use real business tables (customers, products, orders) so you practise the habits analysts use every day: asking only for the columns you need, giving them readable names and returning each value once.
Key ideas
- SELECT … FROM
- Pick columns from a table. Use * only when exploring; name columns in real queries.
- AS (aliases)
- Rename a column or expression in the output, e.g. price * 0.9 AS sale_price.
- DISTINCT
- Return each distinct row once: the cities you have customers in, not every customer.
- ORDER BY
- Sort the result. Without it, the database may return rows in any order.
Example: Every city and state you have customers in
SELECT DISTINCT city, state
FROM customers
ORDER BY state, city;DISTINCT applies to the whole row (city + state together), and ORDER BY sorts by state first, then city.
In interviews
Interviewers notice SELECT *. Naming exactly the columns the question asks for shows you read the requirement and keeps results easy to check.
All 9 SELECT Basics exercises
Ordered from easiest to hardest. Each one runs on a real database with instant feedback.
- 01List All ProductsFreeecommerceEasy
- 02Unique Customer CitiesecommerceEasy
- 03Distinct Shipping CarriersecommerceEasy
- 04List All BranchesfinanceEasy
- 05Unique Bank Customer CitiesfinanceEasy
- 06List All PatientshealthcareEasy
- 07Distinct Blood TypeshealthcareEasy
- 08Distinct DiagnoseshealthcareEasy
- 09Departments Ordered by BudgethealthcareEasy