Built-In Course
Learn SQL while querying real files
SQL for Files includes 80 guided lessons in 17 chapters, with 71 hands-on challenges that check your query result automatically. Lessons open directly in the editor: load sample tables, run SQL with autocomplete, and practice without installing a database.
Practice in the editor
Lessons use the same Monaco editor, DuckDB engine, and results panel as your own imported files.
Load sample data
One-click sample tables make it easy to run examples before bringing your own CSV, JSON, or Parquet files.
Keep data local
Use AI to draft SQL if you want, then run it locally without uploading sensitive file data to an AI provider.
Understanding Data
Build the mental model behind SQL: how tables store rows and columns, why data types matter, and how missing values work with NULL.
Lesson 01 · Theory
Tables, Rows, and Columns
Learn how a database table organizes data into rows and columns, and why that structure is the mental model behind every SQL query.
Lesson 02 · Theory
Data Types
See how SQL data types such as text, integers, decimals, dates, and booleans decide which comparisons, math, and sorting work on a column.
Lesson 03 · Theory
Missing Values with NULL
Understand how SQL represents missing or unknown values with NULL, why NULL is not zero or an empty string, and how to test for it with IS NULL.
Introduction to SQL
Write your first SELECT queries: return rows, choose columns, rename results with aliases, and sort output with ORDER BY.
Lesson 01 · Challenge
Your First Query
Write your first SQL query with SELECT * FROM and return every row and column from a sample employees table directly in your browser.
Lesson 02 · Challenge
Selecting Columns
Practice selecting only the columns you need by listing them after SELECT, and see how the column order in your query shapes the result.
Lesson 03 · Challenge
Naming Results with Aliases
Rename result columns with AS aliases so query output is easier to read, then rename the name and salary columns in a hands-on challenge.
Lesson 04 · Challenge
Sorting Results
Sort query results with ORDER BY, choose ascending or descending order, and sort by several columns to control exactly how rows appear.
Filtering Data
Narrow results to the rows you need with WHERE, combine conditions with AND and OR, and match text patterns with LIKE.
Lesson 01 · Challenge
WHERE Clause Basics
Filter rows with the SQL WHERE clause and comparison operators, then find every employee earning more than 80,000 in a sample table.
Lesson 02 · Challenge
Combining Conditions
Combine filter conditions with AND, OR, and parentheses so a WHERE clause returns exactly the rows you mean, not a broader slice.
Lesson 03 · Challenge
Pattern Matching with LIKE
Match text patterns with LIKE and ILIKE using the % and _ wildcards, and find names that contain a given substring in a SQL challenge.
Simple Aggregates
Summarize a whole table into single values with COUNT, SUM, MIN, MAX, and AVG.
Lesson 01 · Challenge
COUNT Rows
Count rows with COUNT(*) and combine it with WHERE to answer how-many questions, such as how many sales a single region recorded.
Lesson 02 · Challenge
SUM Values
Add up numeric columns with SUM to calculate totals like revenue, and filter first with WHERE to total only one region's sales.
Lesson 03 · Challenge
COUNT and SUM Together
Return several aggregates in one query by combining COUNT and SUM, producing a compact one-row summary of a filtered set of sales.
Lesson 04 · Challenge
MIN Finds the Smallest Value
Find the smallest value in a numeric column with MIN and return it under a clear alias, such as the smallest sale in a sales table.
Lesson 05 · Challenge
MAX Finds the Largest Value
Find the largest value in a column with MAX and alias the result, such as returning the single biggest sale amount from sample data.
Lesson 06 · Challenge
AVG Computes the Mean
Calculate the average of a numeric column with AVG, return it with an alias, and practice reading the mean of a small sales table.
Lesson 07 · Challenge
MIN, MAX, and AVG Together
Combine MIN, MAX, and AVG in one SELECT to summarize the spread of a numeric column with its smallest, largest, and average values.
DISTINCT and GROUP BY
Remove duplicates with DISTINCT, summarize per category with GROUP BY, and filter grouped results with HAVING.
Lesson 01 · Challenge
Removing Duplicates with DISTINCT
Remove duplicate rows with SELECT DISTINCT, see how it applies to the full combination of columns, and list each region exactly once.
Lesson 02 · Challenge
Summarizing with GROUP BY
Summarize rows per category with GROUP BY and SUM, and learn the rule that every selected column must be grouped or aggregated.
Lesson 03 · Challenge
Filtering Groups with HAVING
Filter grouped results with HAVING, learn how it differs from WHERE, and find salespeople with more than one sale using COUNT(*).
Working with Dates
Filter by date ranges, extract parts of dates, and calculate the days between two dates in DuckDB SQL.
Lesson 01 · Challenge
Filtering by Date Ranges
Filter rows by date ranges with comparison operators and DATE literals, and return only the orders placed in one specific month.
Lesson 02 · Challenge
Extracting Parts of a Date
Pull the year, month, or day out of a date with EXTRACT, then group by the extracted part to count how many orders arrived per month.
Lesson 03 · Challenge
Date Arithmetic with DATE_DIFF
Calculate the number of days between two dates with DuckDB's DATE_DIFF, such as the shipping time between order and ship dates.
JOIN Types
Combine related tables with INNER, LEFT, RIGHT, FULL OUTER, SELF, and CROSS JOIN, and find rows that have no match.
Lesson 01 · Theory
Why JOINs Exist
Understand why normalized data lives in separate tables and how JOINs reconnect related rows through matching key columns.
Lesson 02 · Challenge
INNER JOIN Basics
Combine two tables with INNER JOIN and an ON condition, keeping only rows that match on both sides, like employees and departments.
Lesson 03 · Challenge
LEFT JOIN Keeps the Left Side
Keep every row from the left table with LEFT JOIN, see unmatched rows filled with NULL, and list departments even without employees.
Lesson 04 · Challenge
Finding Missing Matches
Use a LEFT JOIN with a WHERE ... IS NULL filter to find rows without a match, such as departments that have no employees yet.
Lesson 05 · Challenge
RIGHT JOIN and FULL OUTER JOIN
Learn how RIGHT JOIN mirrors LEFT JOIN and how FULL OUTER JOIN keeps unmatched rows from both tables in a single result.
Lesson 06 · Challenge
SELF JOIN for Hierarchies
Join a table to itself with table aliases to model a hierarchy, and list each employee next to their manager's name.
Lesson 07 · Challenge
CROSS JOIN for All Combinations
Generate every combination of rows from two tables with CROSS JOIN, such as each department paired with each meeting day.
Window Functions
Calculate totals, running sums, rankings, and previous-row comparisons with OVER and PARTITION BY while keeping every detail row.
Lesson 01 · Challenge
OVER Keeps the Detail Rows
Use a window function with OVER () to show an aggregate like a grand total next to every detail row without collapsing the rows.
Lesson 02 · Challenge
PARTITION BY Creates Mini Windows
Split a window into groups with PARTITION BY to show each sale beside its regional total while keeping every row in the result.
Lesson 03 · Challenge
Running Totals with ORDER BY
Build running totals by adding ORDER BY inside OVER, and calculate cumulative sales for each salesperson over time.
Lesson 04 · Challenge
Ranking Rows with ROW_NUMBER
Number rows inside each group with ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...) to rank sales from largest to smallest.
Lesson 05 · Challenge
Looking Back with LAG
Compare each row with the previous one using LAG, such as showing each salesperson's prior sale amount next to the current sale.
Lesson 06 · Theory
Other Common Window Functions
Review other common window functions, including RANK, DENSE_RANK, NTILE, LEAD, FIRST_VALUE, and LAST_VALUE, and how frames affect them.
Execution Order
Understand the logical order in which SQL evaluates FROM, WHERE, GROUP BY, HAVING, window functions, SELECT, ORDER BY, and LIMIT.
Lesson 01 · Theory
Written Order vs Logical Order
Learn the logical order SQL uses to evaluate a query, from FROM through LIMIT, and why it differs from the order you write clauses.
Lesson 02 · Challenge
FROM and JOIN Build the Rows First
See how FROM and JOIN assemble the working rows before WHERE filters them, then filter joined employee and department data.
Lesson 03 · Challenge
WHERE Filters Before GROUP BY
Learn why WHERE removes individual rows before GROUP BY runs, and total only the larger sales per region in a hands-on query.
Lesson 04 · Challenge
HAVING Filters After GROUP BY
Learn why HAVING filters aggregated groups after GROUP BY, and return only the regions whose total sales exceed a threshold.
Lesson 05 · Challenge
Where Window Functions Fit
See where window functions run in the logical query order, and rank grouped regional totals with RANK() over a GROUP BY result.
Lesson 06 · Challenge
Why Window Functions Cannot Go Directly in WHERE
Learn why window functions cannot appear in WHERE and how a subquery or CTE lets you filter to the top-ranked row in each group.
Lesson 07 · Challenge
Why SELECT Aliases Work in ORDER BY
Learn why a SELECT alias works in ORDER BY but not in WHERE, and sort employees by a calculated annual bonus column.
Lesson 08 · Challenge
LIMIT Happens at the End
Learn why LIMIT applies to the final sorted result, and return the two highest-paid employees in one department with ORDER BY.
Normalization
See why well-designed databases split data into related tables, feel update, insert, and delete anomalies, and learn 1NF, 2NF, and 3NF.
Lesson 01 · Theory
Why Normalization Matters
Understand what database normalization is, why each fact should be stored in one place, and how it prevents inconsistent data.
Lesson 02 · Challenge
Feel the Update Anomaly
Experience an update anomaly in a flat orders table, where one customer's city is repeated on many rows that would all need changing.
Lesson 03 · Challenge
One Row to Update in a Good Schema
See how a normalized customers table turns a risky multi-row update into a change to a single row, then query that one row.
Lesson 04 · Challenge
Feel Why Packed Lists Break 1NF
Discover why comma-separated lists in a single column break first normal form, and why searching them with LIKE is fragile.
Lesson 05 · Challenge
Order Items Feel Better
Model order lines in their own order_items table to satisfy first normal form, then find orders that contain a product with a JOIN.
Lesson 06 · Challenge
Feel the Delete Anomaly
Experience a delete anomaly, where removing an order row would also erase the only record of a product, using GROUP BY and HAVING.
Lesson 07 · Challenge
Products Can Exist Without Orders
See how a separate products table fixes insert and delete anomalies, and find products that have never been ordered with a LEFT JOIN.
Lesson 08 · Theory
1NF, 2NF, and 3NF
Learn what first, second, and third normal form require, with short examples of the dependency problems each normal form removes.
Lesson 09 · Theory
Why We Build Tables in Normal Forms
Review why teams design tables in normal forms, from cleaner updates to better data quality, and when denormalizing is a deliberate trade-off.
GROUPING SETS, ROLLUP, and CUBE
Produce subtotals and grand totals in a single query with GROUPING SETS, ROLLUP, and CUBE.
Lesson 01 · Challenge
Multi-Dimension Aggregates with GROUPING SETS
Compute several groupings in one query with GROUPING SETS, returning totals by region, by product, and a grand total together.
Lesson 02 · Challenge
ROLLUP for Hierarchical Totals
Use ROLLUP to produce hierarchical subtotals and a grand total in one SQL query, such as revenue by region and then by product.
Lesson 03 · Challenge
CUBE for All Combinations
Use CUBE to aggregate every combination of the listed columns, producing all subtotals for region and product in one result.
UNNEST
Flatten DuckDB lists and structs into rows and columns with UNNEST, including recursive flattening and max_depth.
Lesson 01 · Challenge
Unnesting Lists into Rows
Turn each element of a DuckDB list column into its own row with UNNEST, such as giving every product tag a separate row.
Lesson 02 · Challenge
Unnesting Structs into Columns
Expand a STRUCT column into separate columns with UNNEST, such as splitting an address struct into city and zip columns.
Lesson 03 · Challenge
Recursive UNNEST for Nested Data
Flatten nested lists in one step with UNNEST and recursive := true, turning a list of lists into individual values in DuckDB SQL.
Lesson 04 · Challenge
Controlling Depth with max_depth
Control how far UNNEST flattens nested lists with max_depth, expanding only the outer level and keeping the inner lists intact.
Array Lambdas
Transform, filter, and reduce DuckDB list columns with lambda functions such as list_transform, list_filter, and list_reduce.
Lesson 01 · Challenge
Transforming Lists with list_transform
Apply a lambda to every element of a DuckDB list with list_transform, such as doubling each price in an order's price list.
Lesson 02 · Challenge
Filtering Lists with list_filter
Keep only the list elements that match a condition with list_filter and a lambda, such as the prices above 10 in each order.
Lesson 03 · Challenge
Reducing a List with list_reduce
Fold a DuckDB list into a single value with list_reduce, sum each order's prices, and learn why empty lists need a starting value.
Lesson 04 · Challenge
Combining Lambda Functions
Nest list_filter inside list_reduce to build an inline list pipeline, summing only prices above 10 with a starting value of 0.
CASE WHEN Expressions
Add conditional logic to queries with CASE WHEN: label rows, bucket numbers, map codes to readable values, and count or sum only the rows that match.
Lesson 01 · Challenge
CASE WHEN Basics
Use a searched CASE WHEN expression to label each row, such as sorting orders into small, medium, and large buckets based on their amount.
Lesson 02 · Challenge
ELSE, NULL, and Branch Order
Learn why CASE stops at the first matching branch, what happens without ELSE, and why NULL values need an IS NULL check before any comparison.
Lesson 03 · Challenge
Simple CASE for Value Mapping
Map codes to readable labels with the simple CASE form, CASE column WHEN value THEN label, such as grouping order statuses into open and closed.
Lesson 04 · Challenge
Conditional Aggregation
Put CASE inside COUNT and SUM to aggregate only matching rows, building pivot-style reports such as shipped orders and revenue per country.
Subqueries and CTEs
Nest one query inside another with subqueries, test membership with IN and EXISTS, and break long queries into named steps with WITH (common table expressions).
Lesson 01 · Challenge
Subqueries in WHERE
Compare each row with a value computed by another query, such as finding team members who earn more than the overall average salary.
Lesson 02 · Challenge
IN, EXISTS, and the NOT IN Trap
Test whether related rows exist with IN and EXISTS subqueries, and learn why NOT IN returns nothing when the subquery contains a NULL.
Lesson 03 · Challenge
Common Table Expressions with WITH
Name an intermediate result with WITH, then query it like a table, such as computing team salary averages first and filtering them in a second step.
Lesson 04 · Challenge
Correlated Subqueries
Write a subquery that refers to the outer row to compare each person with their own team's average, and see how a CTE join expresses the same idea.
Set Operations: UNION, INTERSECT, EXCEPT
Combine the results of two queries: stack rows with UNION and UNION ALL, find rows both sides share with INTERSECT, and find rows only one side has with EXCEPT.
Lesson 01 · Challenge
UNION vs UNION ALL
Stack the rows of two queries with UNION ALL, remove duplicate rows with UNION, and learn the column rules both sides of a set operation must follow.
Lesson 02 · Challenge
INTERSECT Finds Rows in Both
Use INTERSECT to return only rows that appear in both query results, such as the newsletter subscribers who signed up in two consecutive years.
Lesson 03 · Challenge
EXCEPT Finds Rows Only on One Side
Use EXCEPT to return rows from the first query that are missing from the second, such as subscribers who did not come back the following year.
Lesson 04 · Challenge
Stacking and Summarizing Results
Stack similar tables with UNION ALL and a literal label column, then group the combined rows, and see why UNION would silently drop repeated rows.
String Functions
Clean and reshape text with SQL string functions: change case, trim spaces, concatenate values, extract parts of strings, and replace patterns with regular expressions.
Lesson 01 · Challenge
Changing Case and Trimming Spaces
Normalize messy text with LOWER, UPPER, and TRIM so values that look the same really compare as equal, such as emails with stray capitals and spaces.
Lesson 02 · Challenge
Concatenating Text
Join text values with the || operator, concat, and concat_ws, and learn how each one treats NULL so missing values do not wipe out the whole result.
Lesson 03 · Challenge
Extracting Parts of a String
Pull pieces out of text with LENGTH, LEFT, RIGHT, SUBSTRING, STRPOS, and SPLIT_PART, such as extracting the domain from every email address.
Lesson 04 · Challenge
Cleaning Text with REPLACE and REGEXP_REPLACE
Remove or swap characters with REPLACE, and use REGEXP_REPLACE with the global flag to strip every non-digit from phone numbers in one step.