Learn SQL visually, master it by doing
Watch how it works, interact with a query, then solve the problem.
SELECT basics
Tables, Rows, Columns, and Keys
How data is laid out in a table, and what a primary key does.
SELECT and Projecting Columns
Choosing which columns the result contains.
Filtering Rows with WHERE
Keeping only the rows that match a condition.
Comparison and Logical Operators
Combining conditions with AND, OR, NOT, BETWEEN, IN, and LIKE.
NULL and Three-Valued Logic
Why = NULL never matches, and how AND/OR handle unknown.
ORDER BY and LIMIT / OFFSET
Sorting the result and paging through it.
DISTINCT
Removing duplicate rows from a result.

Learning SQL, 3rd Edition: Generate, Manipulate, and Retrieve Data
Joins
INNER JOIN
Connecting rows whose keys match.
Outer Joins
Keeping unmatched rows with NULLs.
Self Joins
Joining one table to itself through aliases.
CROSS JOIN and All Combinations
Producing every combination of two row sets.
Joining Three or More Tables
Chaining JOINs across several tables.
Join Algorithms
Comparing three ways to match rows.

Practical SQL, 2nd Edition: A Beginner's Guide to Storytelling with Data
Aggregation and grouping
Aggregate Functions
Fold many rows into one value.
GROUP BY
Separate rows into groups with the same value.
HAVING
Filter groups after aggregation.
SELECT Processing Order
Follow an aggregate query in logical processing order.
Window Functions
Calculate ranks and running totals while retaining rows.

SQL for Data Analysis: Advanced Techniques for Transforming Data into Insights
Subqueries, CTEs, set operations
Scalar Subqueries
Use a single value returned by a subquery.
IN, EXISTS, and Correlated Subqueries
Test an inner result for each outer row.
Subqueries in FROM
Use a subquery result as a table.
CTEs and Recursive CTEs
Name an intermediate result and follow parent-child relationships step by step.
Set Operations
Combine two SELECT results vertically.

SQL Cookbook, 2nd Edition: Query Solutions and Techniques for All SQL Users
Changing data
INSERT
Match columns with values and add a row.
UPDATE and DELETE
Choose rows with WHERE, then change or remove them.
UPSERT
Choose insert or update based on a conflict.
RETURNING and Multi-Row Changes
Return several affected rows immediately.
