SQL Crash Course
SELECT, FROM, WHERE Basics
SELECT, FROM, WHERE Basics
SQL is the language of databases. As a tester, you will use it to verify that your application stores, retrieves, and updates data correctly. Even if you never write a stored procedure, knowing enough SQL to query the database alongside your API tests makes you dramatically more effective.
The Basic Query Structure
Every SQL query starts with three clauses:
SELECT column1, column2
FROM table_name
WHERE condition;
- SELECT: What columns to return (or
*for all) - FROM: Which table to query
- WHERE: Which rows to include
Your First Queries
Get all users:
SELECT * FROM users;
Get specific columns:
SELECT id, email, created_at FROM users;
Filter with WHERE:
SELECT * FROM users WHERE is_active = 1;
SELECT * FROM users WHERE email = 'test@example.com';
SELECT * FROM orders WHERE total_amount > 100.00;
Operators in WHERE Clauses
| Operator | Example | Meaning |
|---|---|---|
= | status = 'active' | Exact match |
!= or <> | status != 'deleted' | Not equal |
>, <, >=, <= | age >= 18 | Comparison |
LIKE | email LIKE '%@gmail.com' | Pattern match (% = wildcard) |
IS NULL | deleted_at IS NULL | Null check |
IS NOT NULL | email IS NOT NULL | Not null |
Why Testers Need This
When your API creates a user, you can verify it was stored correctly:
SELECT id, email, role, created_at
FROM users
WHERE email = 'newuser@example.com';
When your API reports an order total, verify the database agrees:
SELECT SUM(price * quantity) as calculated_total
FROM order_items
WHERE order_id = 42;
Direct database verification catches bugs that API-level testing misses — particularly around data persistence and calculation accuracy.
Which SQL query returns all columns for users whose email ends in @gmail.com?
Next Lesson
Filtering with AND, OR, IN, BETWEEN