SQL (Structured Query Language) is essential for anyone working with data. Whether you're a developer, analyst, or aspiring data scientist, SQL skills are in high demand.
Basic SQL Commands
SELECT - Retrieve Data
SELECT column1, column2 FROM table_name;
SELECT * FROM customers;
WHERE - Filter Results
SELECT * FROM products WHERE price > 100;
SELECT * FROM users WHERE country = 'USA';
ORDER BY - Sort Results
SELECT * FROM products ORDER BY price DESC;
LIMIT - Restrict Results
SELECT * FROM orders LIMIT 10;
Aggregation Functions
COUNT()- Count rowsSUM()- Add valuesAVG()- Calculate averageMAX()/MIN()- Find extremes
GROUP BY
Group results for aggregation:
SELECT category, COUNT(*) FROM products GROUP BY category;
HAVING
Filter grouped results:
SELECT category, AVG(price) FROM products GROUP BY category HAVING AVG(price) > 50;
JOIN Operations
INNER JOIN
Match rows from both tables:
SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.id;
LEFT JOIN
All rows from left table, matched from right:
SELECT * FROM customers LEFT JOIN orders ON customers.id = orders.customer_id;
RIGHT JOIN
All rows from right table, matched from left.
FULL OUTER JOIN
All rows from both tables.
Data Manipulation
INSERT
INSERT INTO users (name, email) VALUES ('John', 'john@email.com');
UPDATE
UPDATE products SET price = 99 WHERE id = 5;
DELETE
DELETE FROM orders WHERE status = 'cancelled';
Free Practice Resources
- SQLZoo: Interactive SQL tutorials
- W3Schools SQL: Beginner tutorials
- LeetCode SQL: Practice problems
- Mode Analytics: SQL tutorial with real data
- HackerRank: SQL challenges
SQL is one of the most practical skills you can learn. Start with SELECT queries, practice daily, and you'll be querying like a pro! ?