SQL Interview Prep: 1-Hour Cheat Sheet + Mock Questions
Common SQL Commands
SELECT - Fetches data from a table
INSERT INTO - Adds new data
UPDATE - Edits existing data
DELETE - Deletes data
CREATE TABLE - Creates a new table
ALTER TABLE - Adds/modifies columns
DROP TABLE - Deletes a table
Clauses
WHERE - Filters rows (e.g. WHERE age > 25)
ORDER BY - Sorts the result (e.g. ORDER BY name ASC)
GROUP BY - Groups rows (e.g. GROUP BY department)
HAVING - Filters grouped data (e.g. HAVING COUNT(*) > 2)
LIMIT - Limits rows returned (e.g. LIMIT 5)
Aggregate Functions
SELECT COUNT(*), MAX(salary), MIN(salary), AVG(salary), SUM(salary) FROM employees;
JOINs
-- INNER JOIN
SELECT [Link], [Link]
FROM employees a
JOIN salaries b ON [Link] = b.emp_id;
-- LEFT JOIN
SELECT [Link], [Link]
FROM employees a
LEFT JOIN salaries b ON [Link] = b.emp_id;
Keys & Normalization
Primary Key - Uniquely identifies each row in a table.
Foreign Key - References a primary key from another table.
Normalization - Organizing data to reduce redundancy (e.g., 1NF, 2NF, 3NF).
Quick Mock Interview Questions
Easy:
1. Select all columns from a table called users.
2. Get names of employees with salary > 50,000.
3. Count employees in each department.
4. Retrieve top 3 highest-paid employees.
Intermediate:
5. Difference between WHERE and HAVING?
6. What is GROUP BY used for?
SQL Interview Prep: 1-Hour Cheat Sheet + Mock Questions
7. Join orders and customers using customer_id.
8. Find departments with more than 5 employees.
Advanced:
9. What is indexing and its use?
10. Explain normalization with 1NF, 2NF examples.
Power Tip for Interviews
Speak your thoughts aloud. For example: "I would first filter using WHERE, then group with GROUP BY, and apply
HAVING..."