SQL Interview Guide
Master SQL queries, joins, subqueries, indexes, transactions, and database design principles with examples.
Introduction
SQL (Structured Query Language) is essential for backend development. This guide covers the SQL concepts commonly asked in interviews.
Basic Queries
-- SELECT statement
SELECT * FROM users;
SELECT name, email FROM users WHERE age > 18;
-- INSERT statement
INSERT INTO users (name, email) VALUES ('John', 'john@example.com');
-- UPDATE statement
UPDATE users SET email = 'newemail@example.com' WHERE id = 1;
-- DELETE statement
DELETE FROM users WHERE id = 1;Joins
Joins combine rows from multiple tables based on a related column.
- INNER JOIN - returns matching records
- LEFT JOIN - returns all from left table
- RIGHT JOIN - returns all from right table
- FULL OUTER JOIN - returns all matching and non-matching
Indexes
Indexes speed up queries but slow down write operations. Use them wisely on frequently queried columns.