Learn the SQL a manual tester really needs, from SELECT and WHERE to JOINs, GROUP BY and NULL traps, then find real bugs in a practice food delivery database right in your browser.
beginner Mobile & web
Short on time? Switch to the quick version.
Your progress
It’s Thursday afternoon at FoodDash, a food delivery app. A support ticket comes in: “I was charged €33.50, but my receipt only adds up to €30.” Your lead pings you: “The app looks fine to me. Can you check order 1007 in the database and tell me what was actually saved?”
The practice database in this lesson belongs to FoodDash and has five tables: users, restaurants, coupons, orders and order_items. A column that may be empty holds NULL, which means “no value”.
A column may allow NULL, meaning “no value”. In FoodDash, users.city and orders.coupon_id can be NULL.
Check this part
What does the value in orders.user_id hold?
user_id is a foreign key: it stores the primary key of a row in another table, here the user who placed the order.
What is a primary key for?
Every table has a primary key, usually id, that is unique per row. Other tables point to it with foreign keys.
A database is a set of tables: rows are things, columns are properties, and primary and foreign keys connect one table to another.
Part Not started
Reading data: SELECT, WHERE and ORDER BY
The clauses you’ll use most
SELECT id, status, total -- which columnsFROM orders -- which tableWHERE status = 'delivered' -- which rows AND total > 20ORDER BY total DESC -- sort, highest firstLIMIT 10; -- only the first 10
They always appear in this order. Text goes in single quotes; numbers don’t. Without ORDER BY, rows can come back in any order.
You want…
Write
Exact match / not equal
city = 'Berlin', status <> 'canceled'
A pattern
email LIKE '%@mail.test'
One of a list
status IN ('preparing', 'on_the_way')
A range (inclusive)
total BETWEEN 10 AND 20
An empty value
city IS NULL (never = NULL)
SELECT: reading data
Every read starts with SELECT (which columns) and FROM (which table):
SELECT * FROM restaurants; -- every columnSELECT name, city FROM restaurants; -- only these twoSELECT name AS restaurant, rating FROM restaurants; -- rename a column in the resultSELECT DISTINCT city FROM restaurants; -- each city once
* is handy for a first look, but on real tables with 40 columns, pick the ones you need.
AS gives a column a friendlier name in the result. It doesn’t change the table.
DISTINCT removes duplicate result rows. SELECT DISTINCT city FROM restaurants lists Belgrade, Novi Sad and Berlin once each.
End each query with a semicolon ;. Keywords aren’t case-sensitive (select works), but writing them in capitals makes queries easier to read.
WHERE: picking the rows you need
WHERE keeps only the rows where a condition is true.
Operator
Example
Meaning
=
status = 'delivered'
Equal
<> (or !=)
status <> 'canceled'
Not equal
><>=<=
total >= 20
Greater / smaller
LIKE
email LIKE '%@mail.test'
Matches a pattern
IN
status IN ('preparing', 'on_the_way')
Any value in the list
BETWEEN
total BETWEEN 10 AND 20
In a range, both ends included
IS NULL
coupon_id IS NULL
Has no value
IS NOT NULL
coupon_id IS NOT NULL
Has a value
Combine conditions with AND, OR and NOT. When you mix AND and OR, use brackets, because AND is evaluated first:
-- Delivered or on the way, AND over 20 eurosSELECT id, status, totalFROM ordersWHERE (status = 'delivered' OR status = 'on_the_way') AND total > 20;
Without the brackets you would get every on-the-way order over 20 plus every delivered order of any size. That’s a classic wrong-result bug in testers’ own queries.
LIKE patterns
% matches any number of characters (even none) and _ matches exactly one.
Pattern
Matches
'Mia%'
Starts with “Mia”
'%@mail.test'
Ends with “@mail.test”
'%pizza%'
Contains “pizza” anywhere
'_ana%'
Any first letter, then “ana”: Dana, Hana, Jana…
Dates
In most databases, you write dates as text in the ISO format 'YYYY-MM-DD', and comparisons work as expected:
Watch out with BETWEEN on date-time columns: created_at BETWEEN '2025-09-01' AND '2025-09-07' stops at midnight at the start of September 7, so orders placed later that day are missed. Use created_at < '2025-09-08' for the upper limit instead.
ORDER BY and LIMIT
Without ORDER BY, the database may return rows in any order, and that order can change between runs. If the order matters, say so:
SELECT id, totalFROM ordersORDER BY total DESC, id ASC -- highest total first; ties sorted by idLIMIT 5; -- the top five
ASC (smallest first) is the default. LIMIT works in PostgreSQL, MySQL and SQLite. SQL Server uses SELECT TOP 5 ..., and both SQL Server and Oracle support OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY (Oracle also allows the shorter FETCH FIRST 5 ROWS ONLY).
Check this part
Does total BETWEEN 10 AND 20 include orders with a total of exactly 10 or 20?
BETWEEN is inclusive: it matches 10, 20 and everything in between.
You need rows in a fixed order every time you run the query. What must you add?
Without ORDER BY, the database may return rows in any order, and that order can change between runs.
The SELECT, FROM, WHERE, ORDER BY and LIMIT clauses, always in that order, with text in single quotes.
Part Not started
Counting and totals: aggregates, GROUP BY and HAVING
SELECT status, COUNT(*) AS ordersFROM ordersGROUP BY status;
COUNT, SUM, AVG, MIN and MAX summarize rows. GROUP BY gives one result row per group. WHERE filters rows before grouping; HAVING filters groups after it, for example HAVING COUNT(*) > 1.
Aggregate functions turn many rows into one value:
Function
Example
Returns
COUNT(*)
SELECT COUNT(*) FROM orders
Number of rows (15)
COUNT(column)
SELECT COUNT(coupon_id) FROM orders
Rows where that column is not NULL
SUM
SELECT SUM(total) FROM orders WHERE status = 'delivered'
The sum
AVG
SELECT AVG(rating) FROM restaurants
The average
MIN / MAX
SELECT MIN(created_at), MAX(created_at) FROM orders
The smallest / largest
GROUP BY
GROUP BY splits the rows into groups and runs the aggregate once per group:
SELECT status, COUNT(*) AS orders, SUM(total) AS revenueFROM ordersGROUP BY status;
status
orders
revenue
canceled
2
22.9
delivered
10
201.4
on_the_way
1
16.9
preparing
2
27.1
Rule of thumb: every column in SELECT must either be inside an aggregate or listed in GROUP BY. (SQLite and older MySQL setups let you break this rule and quietly return a random value from the group. Don’t rely on it.)
This is exactly how you test a dashboard: if the admin panel says “11 delivered orders” and your query says 10, someone is counting wrong.
WHERE vs HAVING
WHERE filters rows before they are grouped. HAVING filters groups after the aggregates are calculated.
HAVING for conditions on aggregates
SELECT user_id, COUNT(*) AS ordersFROM ordersWHERE status <> 'canceled' -- rowsGROUP BY user_idHAVING COUNT(*) >= 2; -- groups
Users with at least two non-canceled orders.
Aggregates in WHERE
SELECT user_id, COUNT(*)FROM ordersWHERE COUNT(*) >= 2GROUP BY user_id;
Error: “misuse of aggregate”. When WHERE runs, nothing has been counted yet.
Check this part
What does HAVING do that WHERE can't?
WHERE filters single rows before grouping. HAVING filters the groups afterwards, so it can use COUNT, SUM and the other aggregates.
What does SELECT status, COUNT(*) FROM orders GROUP BY status return?
GROUP BY splits the rows into groups and runs the aggregate once per group, so you get one result row per status.
COUNT, SUM and friends summarize rows; GROUP BY makes one row per group, and HAVING filters the groups.
-- Orders that have no items (a bug!)SELECT o.idFROM orders oLEFT JOIN order_items oi ON oi.order_id = o.idWHERE oi.id IS NULL;
Real questions span several tables: “Which customer placed this order at which restaurant?” A JOIN matches rows using the keys:
SELECT o.id, u.name AS customer, r.name AS restaurant, o.totalFROM orders oJOIN users u ON u.id = o.user_idJOIN restaurants r ON r.id = o.restaurant_idWHERE o.id = 1007;
orders o gives the table a short alias, so you can write o.id instead of orders.id.
The ON condition says how rows belong together: foreign key = primary key.
When two tables have a column with the same name (name, id), you must prefix it, or you’ll get an “ambiguous column name” error.
INNER JOIN vs LEFT JOIN
JOIN on its own means INNER JOIN: only rows that have a partner on both sides. A LEFT JOIN keeps every row from the left (first) table, and when there’s no partner, the right side’s columns are NULL. Try the three versions:
orders
id
total
1001
21.40
1009
9.50
1010
13.40
order_items
id
order_id
dish
1
1001
Margherita
2
1001
Diavola
17
1009
Margherita
SELECT o.id, o.total, oi.dish
FROM orders o
JOIN order_items oi ON oi.order_id = o.id;
Result: 3 rows
id
total
dish
1001
21.40
Margherita
1001
21.40
Diavola
1009
9.50
Margherita
Only orders that have a matching item. Order 1010 has none, so it silently disappears from the result.
That difference is the heart of many tester queries:
Find what’s missing:LEFT JOIN + WHERE right_side.id IS NULL finds orders without items, users who never ordered, restaurants with no orders.
Beware of hidden rows: an INNER JOIN silently drops the broken order. If your “orders per restaurant” report uses an inner join, a restaurant with zero orders won’t appear at all instead of showing 0.
-- Users who have never placed an orderSELECT u.id, u.nameFROM users uLEFT JOIN orders o ON o.user_id = u.idWHERE o.id IS NULL;
Check this part
Which query lists the orders that have no items?
A LEFT JOIN keeps every order and fills the item columns with NULL when there's no match. An INNER JOIN drops those orders before WHERE even runs.
You INNER JOIN orders with order_items. What happens to an order that has no items?
An INNER JOIN keeps only rows with a match on both sides, so the broken order silently disappears. Use a LEFT JOIN to see it.
INNER JOIN keeps matches only; LEFT JOIN plus IS NULL finds what is missing.
Part Not started
NULL: the trap behind many wrong results
NULL means “no value”: it isn’t 0 and it isn’t an empty string. Nothing equals NULL, not even NULL, so WHERE city = NULL silently returns zero rows. Use IS NULL / IS NOT NULL.
NULL means “no value” or “unknown”. It isn’t 0, it isn’t an empty string '', and it doesn’t behave like a normal value. These are the traps that catch testers (and developers) all the time:
Trap
What happens
Do this instead
WHERE coupon_id = NULL
Zero rows, no error
WHERE coupon_id IS NULL
WHERE city <> 'Berlin'
Rows with a NULL city are skipped too (5 rows instead of 7)
Add OR city IS NULL
COUNT(city) vs COUNT(*)
COUNT(city) skips NULLs (8 instead of 10)
Use COUNT(*) to count rows
AVG(rating)
Ignores NULL ratings, it doesn’t treat them as 0
Decide which one the requirement means
NOT IN (SELECT coupon_id FROM orders)
Returns nothing if the list contains a NULL
Use NOT EXISTS or a LEFT JOIN
total + NULL
The result is NULL
COALESCE(discount, 0) replaces NULL with 0
Check this part
You want users who have no city saved. Which condition is correct?
NULL isn't equal to anything, not even NULL, so = NULL never matches. IS NULL is the only reliable check.
What does NULL mean in a database?
NULL means "no value" or "unknown". It isn't 0 or an empty string, and it doesn't behave like a normal value.
NULL means no value: nothing equals it, so use IS NULL and watch for the traps.
Part ProNot started
Typical tester queries
-- Duplicate emails, ignoring capitalizationSELECT LOWER(email), COUNT(*) FROM usersGROUP BY LOWER(email) HAVING COUNT(*) > 1;-- Order items whose order doesn't exist (orphan rows)SELECT oi.* FROM order_items oiLEFT JOIN orders o ON o.id = oi.order_idWHERE o.id IS NULL;-- Orders whose total doesn't match their itemsSELECT o.id, o.total, SUM(oi.quantity * oi.unit_price) AS items_totalFROM orders o JOIN order_items oi ON oi.order_id = o.idGROUP BY o.id, o.totalHAVING ROUND(SUM(oi.quantity * oi.unit_price), 2) <> o.total;
When a query finds a bug, paste the query and its result into the bug report.
These recipes cover most of what testers do with SQL day to day. In the practice database below, each one finds a real bug.
Verify that the UI saved the right data
You place an order in the app, then check exactly what was stored:
Find the record. Use something you know from the UI, like the order number on the confirmation screen: SELECT * FROM orders WHERE id = 1007; If you don’t have an id, use your test user plus time: WHERE user_id = 2 ORDER BY created_at DESC LIMIT 1.
Check every field the screen showed. Status, total, coupon, timestamps. Then check the fields the screen didn’t show, like coupon_id or created_at. Is the time zone right?
Check the related rows.SELECT * FROM order_items WHERE order_id = 1007; Are all dishes there, with the right quantities and prices?
Check that the numbers agree. Does the total match the sum of the items? Did exactly one order get created, not two after a double tap?
Find duplicates
SELECT LOWER(email) AS email, COUNT(*) AS accountsFROM usersGROUP BY LOWER(email)HAVING COUNT(*) > 1;
GROUP BY ... HAVING COUNT(*) > 1 is the universal duplicate finder. Group by whatever should be unique: an email, a coupon code, an order number, a payment id. Use LOWER() or TRIM() when duplicates may hide behind capitals or spaces.
Find orphan rows
SELECT oi.*FROM order_items oiLEFT JOIN orders o ON o.id = oi.order_idWHERE o.id IS NULL;
Add 2 × Spicy tuna roll (10.20) and 2 × Salmon nigiri (4.80) from Sushi Zen Garden
Place the order and note the order number
Run SELECT * FROM orders WHERE id = <order number>
Run SELECT * FROM order_items WHERE order_id = <order number>
Expected result
The app shows a total of 30.00. orders has exactly one new row with status 'preparing' and total 30.00. order_items has exactly 2 rows that add up to 30.00.
TC-DB-02Sign-up rejects an email that differs only in capitalizationnegativehigh
Sometimes the fastest way to reach a precondition (“a user with an expired coupon”) is to create it directly. That’s fine only on a database that is yours: a local copy, a personal test environment, or a shared test database where your team explicitly allows it.
INSERT adds rows, UPDATE changes them and DELETE removes them. A few habits prevent disasters:
Write the SELECT first, check it returns exactly the rows you mean, then turn it into the UPDATE or DELETE with the sameWHERE.
Never run UPDATE or DELETE without WHERE. Without it, every row in the table changes.
Mark your data with a prefix like QA_, so it’s easy to find and clean up.
Never touch production data.
Try it safely in the practice database below: it’s your own copy, and Reset database undoes everything.
-- Create a test coupon that has already expiredINSERT INTO coupons (id, code, percent, once_per_user, valid_until)VALUES (90, 'QA_EXPIRED', 10, 1, '2025-01-31');-- Move one test order to another statusUPDATE orders SET status = 'canceled' WHERE id = 1013;-- Remove the test coupon againDELETE FROM coupons WHERE id = 90;
You can try all three statements in the playground below. It’s your own copy, and Reset database undoes everything.
Tools you’ll meet at work
DBeaver (free, works with almost every database), pgAdmin (PostgreSQL), MySQL Workbench (MySQL), SQL Server Management Studio (SQL Server) and DataGrip (paid, by JetBrains).
Many teams also have an admin panel that shows the same data. It’s convenient, but it may hide fields or apply its own logic. SQL shows you the raw truth.
Save useful queries in a shared file or wiki page. A team “query cookbook” pays off quickly.
Common mistakes
Check this part
You're about to run an UPDATE on your own test database. What should you do first?
Writing the SELECT first shows you exactly which rows the UPDATE will change, before anything is changed.
What happens if you run DELETE FROM coupons; without a WHERE?
Without WHERE, UPDATE and DELETE apply to every row in the table.
Change data only on a database that is yours: SELECT first, never UPDATE or DELETE without WHERE.
The rest of this lesson is in Bugwise Pro
The last parts of every lesson are part of Bugwise Pro. Sign in to unlock them if you have it.
Time to use it. Below is a real SQLite database running in your browser, filled with FoodDash data. Some of that data is broken in ways that real apps get broken. Work through the 10 exercises: the first five practice the basics, the last five are bug hunts.
Press Run (or Ctrl/⌘ + Enter) to see your result, and Check answer to compare it with the expected result.
Column names and column order don’t matter. Row order only matters when the task says so.
Want to experiment with UPDATE or DELETE? Go ahead: it’s your private copy, and Reset database restores it. Checks always use the original data.
FoodDash practice DB
SQLite, running in your browser
Loading the database engine (about 700 KB, once)…
0 / 10 solved
Exercise 1Easy
Restaurants in Belgrade
Show the name and rating of every restaurant in Belgrade.
Return: namerating(column names and order don't matter)
Ready for more? SQL for Testers 2 covers joins across many tables, EXISTS, WITH, CASE, window functions, time zones and a lab with real payment bugs.
Before you run a query at work
SQL safety and accuracy checklist
0 of 9 checked
Key takeaways
Testers use SQL to verify what the app saved, find test data, check preconditions and investigate bugs.
Read, don’t write: no UPDATE or DELETE on shared or production databases. Use a read-only user and your own test database for experiments.
SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY … LIMIT is the order to remember. Text goes in single quotes.
WHERE filters rows, HAVING filters groups. GROUP BY … HAVING COUNT(*) > 1 finds duplicates.
INNER JOIN keeps matches only; LEFT JOIN + IS NULL finds what’s missing: orders without items, orphan rows, users who never ordered.
NULL is not a value: use IS NULL, and remember that <>, COUNT(column) and NOT IN treat it in surprising ways.
Paste your query and its result into the bug report. It makes the bug easy to reproduce and proves where it lives.
Finished this page?Nice work, this page is complete!
Mark it as done to track your progress. It's saved in this browser, no account needed.