Sample Database Used in This Article
Let’s assume we have a table called users.
users
| id | name | age | city | status | |
|---|---|---|---|---|---|
| 1 | Mrunal | mrunal@test.com | 28 | Pune | Active |
| 2 | Priya | priya@test.com | 25 | Mumbai | Active |
| 3 | Amit | amit@test.com | 31 | Pune | Inactive |
| 4 | Sneha | sneha@test.com | 27 | Delhi | Active |
| 5 | Neha | neha@test.com | 30 | Pune | Active |
We’ll use this example throughout the article.
1. SELECT Query
The SELECT statement is one of the most important SQL commands for a QA Engineer.
It is used to retrieve data from a table.
Query
SELECT * FROM users;
This returns all columns and all records from the users table.
QA Use Case
Suppose you create a new user from the application.
After registration, you can run:
SELECT * FROM users;
and verify whether the user was inserted into the database.
Interview Tip
Be comfortable with SELECT. It is probably the SQL command you will use most frequently as a tester.
2. SELECT Specific Columns
You don’t always need every column.
You can select only the information you want.
SELECT name, email, city
FROM users;
This returns only:
- Name
- City
Why is this useful for QA?
It makes large datasets easier to read.
For example, while validating registration functionality, you may only need:
SELECT name, email
FROM users;
3. WHERE Clause
The WHERE clause allows you to filter records.
SELECT *
FROM users
WHERE city = 'Pune';
This returns users whose city is Pune.
QA Scenario
Suppose your application contains a city filter.
The UI shows:
Pune — 3 users
You can verify the database using:
SELECT *
FROM users
WHERE city = 'Pune';
You can then compare the application result with the database result.
4. AND Condition
The AND operator allows you to apply multiple conditions.
SELECT *
FROM users
WHERE city = 'Pune'
AND status = 'Active';
This returns users who:
- Live in Pune
- AND have Active status
QA Scenario
Imagine an admin page has a filter:
City = Pune
Status = Active
You can validate the result using the above query.
5. OR Condition
OR is used when any one of multiple conditions can be true.
SELECT *
FROM users
WHERE city = 'Pune'
OR city = 'Mumbai';
This returns users from either Pune or Mumbai.
QA Scenario
Suppose the application allows users to select multiple cities.
You can verify whether the backend returns the correct records.