SQL Cheat Sheet for QA Engineers
| SQL Concept | Example |
|---|---|
| SELECT | SELECT * FROM users; |
| WHERE | WHERE city = 'Pune' |
| AND | WHERE city='Pune' AND status='Active' |
| OR | WHERE city='Pune' OR city='Mumbai' |
| ORDER BY | ORDER BY age DESC |
| COUNT | COUNT(*) |
| DISTINCT | SELECT DISTINCT city |
| LIKE | WHERE name LIKE 'A%' |
| BETWEEN | WHERE age BETWEEN 25 AND 30 |
| IN | WHERE city IN ('Pune','Mumbai') |
| UPDATE | UPDATE users SET city='Pune' WHERE id=1 |
| DELETE | DELETE FROM users WHERE id=1 |
| IS NULL | WHERE email IS NULL |
| GROUP BY | GROUP BY city |
| HAVING | HAVING COUNT(*) > 1 |
| INNER JOIN | INNER JOIN orders ON users.id=orders.user_id |
| LEFT JOIN | LEFT JOIN orders ON users.id=orders.user_id |
| Subquery | Query inside another query |
| MIN | MIN(age) |
| MAX | MAX(age) |
How to Practice SQL as a QA Engineer
Don’t just read SQL queries.
Write them yourself.
Create a small practice database and start with one table.
For example:
CREATE TABLE users (
id INT,
name VARCHAR(100),
email VARCHAR(100),
age INT,
city VARCHAR(50),
status VARCHAR(20)
);
Insert some test data:
INSERT INTO users
VALUES
(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');
Then practice every query from this article.
Try to modify the queries instead of simply copying them.
For example:
Challenge 1: Find all active users.
Challenge 2: Find users from Pune.
Challenge 3: Find users older than 28.
Challenge 4: Find duplicate emails.
Challenge 5: Count users from each city.
Challenge 6: Find users whose names start with S.
Challenge 7: Find users between age 25 and 30.
These small exercises will improve your SQL skills much faster than simply memorizing syntax.