Stop 05 · SQL & Databases for QATopics · 1/8

SQL Fundamentals for Testers

Part of the QA Testing Roadmap

In short

The screen says 'Order placed'. But did the database actually save the right price, quantity and status? A few lines of SQL let you check for yourself.

The core statement pattern — SELECT, WHERE, ORDER BY — enough to verify that data displayed in an application actually matches what's stored in the database, a common and essential testing task.

The purple blob leans over a kirana shop counter to look at a big open ledger book.

Think of it like this

Checking the kirana ledger

The shopkeeper says 'I've noted your udhaar'. You lean over and read the ledger: your name, today's date, Rs 240. SQL is how you read the app's ledger instead of trusting what the counter says.

Watch it happen

Checking what the UI claims

Tester
App UI
Database

Place order, qty 2

1/4The tester places an order for two T-shirts through the app.

The big ideas

What you need to know

Tables, rows, columns

A table is like a sheet: each row is one record, each column one field like email or total.

SELECT picks columns

SELECT lists the columns you want, FROM says which table.

WHERE filters rows

WHERE keeps only matching rows, like id = 42 or status = 'FAILED'.

ORDER BY sorts

ORDER BY created_at DESC puts the newest first. LIMIT keeps just the top few.

See it in code

Walk through the code

sql
1-- Did order 42 save what the UI showed?2SELECT id, user_id, quantity, total_amount, status3FROM orders4WHERE id = 42;5 6-- Latest 5 orders for test user 7, newest first7SELECT id, total_amount, created_at8FROM orders9WHERE user_id = 710ORDER BY created_at DESC11LIMIT 5;

1/3Fetch one exact row by its id and compare each column with the UI.

Two everyday tester queries. LIMIT works in PostgreSQL, MySQL and SQLite; SQL Server uses TOP instead.

Save yourself the pain

Common mistakes

Oops

Running UPDATE or DELETE on a shared test database to 'fix' data quickly.

Do this instead

Stick to SELECT unless you're sure and allowed. Changing shared data can break other people's tests.

Oops

Trusting the UI message as proof the data is right.

Do this instead

For key flows like payments and orders, confirm the stored values with a query.

Your mission

Query a practice database

~30 min

Quick check

Which query returns only failed orders, newest first?

Go deeper

  1. 1Write 10 basic SELECT queries against a free sample database.
  2. 2Practice combining multiple WHERE conditions with AND/OR.
  3. 3Learn why testers who can query the database directly work significantly faster than those who can't.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge