Bonus: SQL Queries Every QA Engineer Should Practice
The 20 queries above cover the most important fundamentals, but don’t stop there.
As you become more comfortable with SQL, practice:
MIN()
Find the minimum value:
SELECT MIN(age)
FROM users;
MAX()
Find the maximum value:
SELECT MAX(age)
FROM users;
AVG()
Find the average:
SELECT AVG(age)
FROM users;
SUM()
Calculate a total:
SELECT SUM(amount)
FROM orders;
These functions are especially useful while testing reports, dashboards, financial calculations, and analytics features.
Real-World SQL Testing Example
Let’s consider a simple e-commerce application.
A customer places an order.
The UI displays:
Order placed successfully
Order ID: 5001
Amount: ₹1,499
As a QA Engineer, you should not stop at the UI.
You can validate the database.
Step 1: Check whether the order exists
SELECT *
FROM orders
WHERE order_id = 5001;
Step 2: Validate the customer
SELECT *
FROM users
WHERE id = 101;
Step 3: Validate the order amount
SELECT amount
FROM orders
WHERE order_id = 5001;
Step 4: Validate order status
SELECT status
FROM orders
WHERE order_id = 5001;
Expected:
PLACED
This is an example of backend/database validation.
SQL Testing Example: Registration
Imagine you are testing a registration form.
The user enters:
Name: Sneha
Email: sneha@test.com
City: Pune
After clicking Register, the application displays:
Registration successful.
Now execute:
SELECT name, email, city
FROM users
WHERE email = 'sneha@test.com';
Expected:
Sneha | sneha@test.com | Pune
If the database contains:
Sneha | sneha@test.com | Mumbai
then there may be a defect because the city saved in the database does not match the submitted value.
SQL Testing Example: Delete User
Suppose you delete user ID 10 from the application.
Before deletion:
SELECT *
FROM users
WHERE id = 10;
The record exists.
Perform the delete operation through the UI.
Then execute:
SELECT *
FROM users
WHERE id = 10;
If no record is returned, you have confirmed that the record was removed from the database.
SQL Testing Example: Duplicate Email
Suppose the requirement says:
A user cannot register with an email that already exists.
You can check existing duplicate emails with:
SELECT email, COUNT(*)
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
If the query returns any email, investigate whether duplicate data exists.
SQL Testing Example: API + Database Validation
SQL is also extremely useful for API testing.
Imagine a POST API creates a customer.
The API response says:
{
"id": 101,
"name": "Mrunal",
"status": "Active"
}
You can validate the database:
SELECT id, name, status
FROM customers
WHERE id = 101;
Expected:
101 | Mrunal | Active
``