📗 SQL Basics – Quick Reference & Study
Guide
1. Introduction to SQL
● SQL (Structured Query Language) is the standard language for working with relational
databases.
● It allows you to define structures (DDL), manipulate data (DML), and query
information efficiently.
2. Core SQL Commands
● SELECT – Retrieve data from a table.
● INSERT – Add new rows into a table.
● UPDATE – Modify existing records.
● DELETE – Remove records from a table.
● JOIN – Combine rows from multiple tables based on related columns.
3. Filtering & Aggregation
SELECT department, COUNT(*)
FROM employees
WHERE salary > 50000
GROUP BY department
ORDER BY COUNT(*) DESC;
● WHERE filters records.
● GROUP BY groups data for aggregation (SUM, AVG, COUNT).
● ORDER BY sorts results.
4. Types of Joins
● INNER JOIN – Matches records in both tables.
● LEFT JOIN – All records from the left table, plus matched records.
● RIGHT JOIN – All records from the right table, plus matched records.
● FULL OUTER JOIN – All records with matches in either table.
5. Best Practices
● Avoid SELECT *, specify needed columns.
● Use aliases (AS) for readability.
● Use indexes for performance.
● Normalize data to reduce redundancy.