SQL Cheat Sheet for QA Engineers

SQL ConceptExample
SELECTSELECT * FROM users;
WHEREWHERE city = 'Pune'
ANDWHERE city='Pune' AND status='Active'
ORWHERE city='Pune' OR city='Mumbai'
ORDER BYORDER BY age DESC
COUNTCOUNT(*)
DISTINCTSELECT DISTINCT city
LIKEWHERE name LIKE 'A%'
BETWEENWHERE age BETWEEN 25 AND 30
INWHERE city IN ('Pune','Mumbai')
UPDATEUPDATE users SET city='Pune' WHERE id=1
DELETEDELETE FROM users WHERE id=1
IS NULLWHERE email IS NULL
GROUP BYGROUP BY city
HAVINGHAVING COUNT(*) > 1
INNER JOININNER JOIN orders ON users.id=orders.user_id
LEFT JOINLEFT JOIN orders ON users.id=orders.user_id
SubqueryQuery inside another query
MINMIN(age)
MAXMAX(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.


Pages: 1 2 3 4 5 6 7 8 9

Leave a Reply

Your email address will not be published. Required fields are marked *