📄️ Introduction
SQL (Structured Query Language) is a standard language for storing, manipulating, and retrieving data in relational databases.
📄️ Databases & Tables
Database Operations
📄️ CRUD Operations
INSERT — Create
📄️ Filtering & Sorting
WHERE Clause
📄️ Aggregate Functions
Common Aggregates
📄️ Joins
Joins combine rows from two or more tables based on a related column.
📄️ Subqueries
A subquery is a query nested inside another query.
📄️ String Functions
SQL string functions allow manipulation, transformation, and extraction of text data.
📄️ Number Functions
SQL number functions allow performing mathematical operations and formatting numerical values.
📄️ Date & Time Functions
SQL provides extensive functions for extracting, formatting, and calculating date and time values.
📄️ Handling NULLs
NULL represents missing or unknown data. It is not the same as zero or an empty string. Proper NULL handling is essential for data integrity.
📄️ CASE Statements
The CASE statement adds conditional logic to SQL queries — similar to IF/ELSE in other languages.
📄️ SET Operations
SET operations combine results from multiple queries into a single result set.
📄️ Window Functions — Basics
Window functions perform calculations across a set of rows related to the current row — without collapsing them into groups like GROUP BY.
📄️ Window Aggregations
Use aggregate functions (COUNT, SUM, AVG, MIN, MAX) as window functions to retain row-level detail alongside aggregated values.
📄️ Window Ranking
Ranking functions assign positions to rows based on ordering, enabling top-N analysis, deduplication, and segmentation.
📄️ Window Value Functions
Value functions let you access data from other rows in the result set without self-joins, enabling time series analysis and comparisons.
📄️ Common Table Expressions (CTEs)
CTEs provide a way to write modular, readable queries using the WITH clause. They act as named temporary result sets that exist only for the duration of the query.
📄️ Views
A view is a virtual table defined by a query. It does not store data — it runs the underlying query each time it is accessed.
📄️ Temporary Tables
Temporary tables are used to stage, transform, and clean data before loading it into permanent tables. They exist only for the duration of the session.
📄️ Stored Procedures
Stored procedures are reusable blocks of SQL logic saved in the database. They accept parameters, support control flow, and handle errors.
📄️ Triggers
Triggers are automated actions that fire in response to data changes (INSERT, UPDATE, DELETE) on a table.
📄️ Indexes
Indexes speed up data retrieval by creating an organized lookup structure, similar to an index in a book.
📄️ Partitioning
Partitioning divides a large table into smaller physical segments based on a column value (e.g., date). Queries can then skip irrelevant partitions (partition elimination), improving performance.
📄️ 30 Performance Tips
A categorized guide to writing faster SQL queries.
📄️ AI & SQL
A collection of 16 prompt templates for using AI tools (ChatGPT, Copilot, Claude) to accelerate SQL development and learning.