The SELECT statement is the most frequently used SQL command.
If SQL is a language, SELECT is the sentence you’ll write the most.
In this article, you’ll learn how to:
This is Part 03 of the SQL from Zero to Pro series.
The SELECT statement retrieves data from one or more tables.
SELECT column_name
FROM table_name;
Example
SELECT name
FROM customers;
What this means:
Selecting all columns
SELECT * FROM employees;
⚠️
SELECT *is useful for learning, but should be avoided in production queries.
SELECT first_name, last_name
FROM employees;
Benefits:
The WHERE clause filters rows based on a condition.
Basic example
SELECT *
FROM employees
WHERE department = 'HR';
Plain English:
employeesdepartment is HRSQL uses comparison operators to filter values.
| Operator | Meaning | Example |
|---|---|---|
| = | Equal to | department = ‘HR’ |
| != or <> | Not equal | status != ‘inactive’ |
| > | Greater than | salary > 50000 |
| < | Less than | age < 30 |
| >= | Greater or equal | price >= 100 |
| <= | Less or equal | score <= 60 |
Example
SELECT name, price
FROM products
WHERE price > 100;
Logical operators allow you to combine conditions.
SELECT *
FROM employees
WHERE department = 'Sales'
AND salary > 60000;
Both conditions must be true.
SELECT *
FROM employees
WHERE department = 'HR'
OR department = 'Finance';
Either condition can be true.
SELECT *
FROM users
WHERE NOT active = true;
Negates a condition.
Filtering text
Text values must be wrapped in quotes.
SELECT *
FROM customers
WHERE country = 'UK';
Text comparisons may be case-sensitive depending on collation.
Filtering dates
SELECT *
FROM orders
WHERE order_date >= '2025-01-01';
Using proper date types allows:
SQL for Developers
Developers focus on:
Common patterns:
SELECT *
FROM users
WHERE id = 42;
SQL for Data Analysts
Analysts focus on:
Common patterns:
SELECT *
FROM sales
WHERE region = 'EU'
AND sale_date >= '2025-01-01';
Exercise 1 – Read the Query
Explain what this query does in plain English:
SELECT email
FROM users
WHERE active = true;
Exercise 2 – Write a filtered query
Write a query to:
name and priceproducts50Exercise 3 – Combine conditions
Write a query that:
Engineering2024-01-01Bonus practice
Experiment with:
> vs >=AND and ORThe SELECT and WHERE clauses form the foundation of SQL querying.
If you can:
You already have the skills needed to query real-world databases.
In the next article (SQL 04), we’ll explore sorting results, limiting rows, and aggregating data, which is where SQL starts answering business-level questions.
Happy querying 🚀
## **Exercise 1 – Read the query (answer)
SELECT email
FROM users
WHERE active = true;
Plain English explanation
users tableactive status is trueemail columnThis query returns the email addresses of all active users.
Exercise 2 – Write a filtered uery (answer)
SELECT name, price
FROM products
WHERE price < 50;
What this query does
50 or higherExercise 3 – Combine conditions (answer)
SELECT *
FROM employees
WHERE department = 'Engineering'
AND hire_date > '2024-01-01';
Plain English explanation
employees tableBonus Practice – Example exploration
Below are a few example queries you might try while experimenting.
Using Greater Than vs Greater Than or Equal To
SELECT *
FROM products
WHERE price >= 100;
Returns products priced at 100 or more, including exactly 100.
Combining AND and OR
SELECT *
FROM employees
WHERE department = 'HR'
OR department = 'Finance'
AND active = true;
⚠️ Important:
ANDis evaluated beforeOR.
To make the logic explicit:
SELECT *
FROM employees
WHERE (department = 'HR' OR department = 'Finance')
AND active = true;
Filtering text vs numeric values
-- Text comparison
SELECT *
FROM customers
WHERE country = 'UK';
-- Numeric comparison
SELECT *
FROM orders
WHERE total_amount > 500;
Text values are quoted, numeric values are not.
Key takeaways
SELECT chooses columnsFROM chooses the tableWHERE filters rowsIf you can confidently read and write these queries, you’re officially querying like a SQL user — not just memorising syntax.
Next up: SQL 04 – ORDER BY, LIMIT, and Aggregations 🚀