Free SQL tutorial

Learn SQL from basics to advanced

40 free lessons that take you from your first SELECT to window functions and interview questions. Every lesson uses the same Indian e-commerce dataset, ShopKart, and every result on the page comes from actually running the query in PostgreSQL.

Module 1

SQL Basics

  1. 1. What is SQL?What is SQL and why do data analysts use it? Learn what databases, tables, rows and columns are, and write your first SQL query in minutes.
  2. 2. SQL Practice Dataset: the ShopKart E-commerce DatabaseFree SQL practice dataset for an Indian e-commerce store: customers, products, orders, order items and employees. Copy the script and start querying.
  3. 3. SQL SELECT StatementLearn the SQL SELECT statement: select specific columns, all columns with *, calculated columns and constants, with real query results.
  4. 4. SQL DISTINCT and AliasesRemove duplicate rows with SQL DISTINCT and rename columns and tables with AS aliases. Clear examples, real results and common mistakes.
  5. 5. SQL WHERE ClauseFilter rows with the SQL WHERE clause. Learn comparison operators, AND, OR, NOT and operator precedence with e-commerce examples and real results.
  6. 6. SQL IN, BETWEEN and LIKEUse SQL IN to match a list, BETWEEN for ranges and LIKE/ILIKE with % and _ wildcards for pattern matching. Real e-commerce examples.
  7. 7. NULL in SQLUnderstand NULL in SQL: why = NULL fails, how IS NULL works, and how to replace or avoid NULLs with COALESCE and NULLIF. Real examples.
  8. 8. SQL ORDER BY and LIMITSort SQL results with ORDER BY (ASC, DESC, multiple columns, NULLS LAST) and return top N rows or pages with LIMIT and OFFSET.

Module 2

SQL Functions

  1. 9. SQL String FunctionsClean and reshape text in SQL with UPPER, LOWER, LENGTH, CONCAT, SUBSTRING, TRIM, REPLACE, POSITION and SPLIT_PART. Examples with real output.
  2. 10. SQL Numeric Functions and CASTDo maths in SQL: arithmetic operators, ROUND, CEIL, FLOOR, ABS, MOD and CAST. Learn the integer division trap with real e-commerce examples.
  3. 11. SQL Date FunctionsWork with dates in SQL: CURRENT_DATE, EXTRACT, DATE_TRUNC, TO_CHAR, date differences and intervals. Monthly sales and delivery-time examples.
  4. 12. SQL CASE WHENAdd if-then-else logic to SQL with CASE WHEN. Bucket values, create labels, sort custom orders and build conditional counts, with real results.

Module 3

Aggregation

  1. 13. SQL Aggregate FunctionsSummarise data with SQL aggregate functions COUNT, SUM, AVG, MIN and MAX. Learn COUNT(*) vs COUNT(column), FILTER and how NULLs are handled.
  2. 14. SQL GROUP BYLearn SQL GROUP BY to calculate totals, counts and averages per group: orders by status, revenue by product, sales by month. Real examples and results.
  3. 15. SQL HAVING ClauseFilter grouped results with SQL HAVING. Understand HAVING vs WHERE, combine both in one query, and find repeat customers and top sellers.

Module 4

Joins

  1. 16. SQL Joins and INNER JOINLearn SQL joins from scratch: what a join is, how ON works, and how INNER JOIN combines customers, orders and products. Real examples and results.
  2. 17. SQL LEFT JOIN and RIGHT JOINLearn SQL LEFT JOIN and RIGHT JOIN: keep all rows from one table, find unmatched records, and avoid the WHERE-vs-ON trap. Real examples.
  3. 18. SQL FULL OUTER JOIN and CROSS JOINLearn SQL FULL OUTER JOIN to keep unmatched rows from both tables, and CROSS JOIN to build every combination, such as month-by-category report grids.
  4. 19. SQL SELF JOINLearn SQL self join with employee-manager hierarchies, pairs of customers in the same city and comparing rows within one table. Real examples.
  5. 20. SQL: Join Multiple TablesJoin three or more tables in SQL step by step: revenue by category, customer purchase history and city-level sales. Avoid double counting.

Module 5

Subqueries & CTEs

  1. 21. SQL SubqueriesLearn SQL subqueries: scalar subqueries, IN subqueries and subqueries in FROM (derived tables). Find above-average products and top customers.
  2. 22. Correlated Subqueries and EXISTSUnderstand correlated subqueries and the EXISTS and NOT EXISTS operators in SQL. Compare rows to their own group and find missing records safely.
  3. 23. SQL CTE (WITH Clause)Write cleaner SQL with CTEs using the WITH clause. Break queries into named steps, chain multiple CTEs and compare CTEs with subqueries.
  4. 24. SQL Recursive CTELearn SQL recursive CTEs with WITH RECURSIVE: walk an org chart, find reporting levels and generate date sequences. Step-by-step examples.
  5. 25. SQL UNION, INTERSECT and EXCEPTCombine query results with SQL set operators: UNION vs UNION ALL, INTERSECT for common rows and EXCEPT for differences. Rules and examples.

Module 6

Window Functions

  1. 26. SQL Window FunctionsLearn SQL window functions from scratch: OVER(), PARTITION BY and ORDER BY inside windows. Show totals, shares and averages next to every row.
  2. 27. ROW_NUMBER, RANK, DENSE_RANK and NTILERank rows in SQL with ROW_NUMBER, RANK, DENSE_RANK and NTILE. See how each handles ties, and solve top-N-per-group and nth-highest problems.
  3. 28. SQL LAG and LEADUse SQL LAG and LEAD to compare each row with the previous or next one: month-over-month growth, days between orders and repeat-purchase gaps.
  4. 29. Running Totals, Moving Averages and Window FramesCalculate running totals, cumulative percentages and moving averages in SQL with window frames: ROWS BETWEEN, UNBOUNDED PRECEDING and LAST_VALUE.

Module 7

Creating & Changing Data

  1. 30. SQL CREATE TABLE and Data TypesCreate tables in SQL with CREATE TABLE and choose the right data types: INT, NUMERIC, VARCHAR, TEXT, DATE, TIMESTAMP, BOOLEAN. Plus CREATE TABLE AS.
  2. 31. SQL ConstraintsProtect data quality with SQL constraints: PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK and DEFAULT. See what each one blocks, with real errors.
  3. 32. SQL INSERT, UPDATE and DELETEAdd, change and remove rows with SQL INSERT, UPDATE and DELETE. Multi-row inserts, INSERT SELECT, UPDATE with joins, RETURNING and upserts.
  4. 33. SQL ALTER TABLE, DROP and TRUNCATEChange table structure with SQL ALTER TABLE: add, rename and drop columns, change types and add constraints. Learn DROP vs TRUNCATE vs DELETE.
  5. 34. SQL TransactionsLearn SQL transactions with BEGIN, COMMIT, ROLLBACK and SAVEPOINT, and what ACID means. Place an order safely so stock and orders always match.

Module 8

Advanced SQL

  1. 35. SQL ViewsSave queries as SQL views with CREATE VIEW, update them with CREATE OR REPLACE, and speed up heavy reports with materialized views and REFRESH.
  2. 36. SQL Indexes and Query OptimizationSpeed up SQL queries with indexes. Learn CREATE INDEX, composite indexes, reading EXPLAIN plans and practical tips to write faster queries.
  3. 37. SQL Functions, Stored Procedures and TriggersWrite user-defined SQL functions, stored procedures with CALL, and triggers in PostgreSQL. Reuse business logic and automate audit logs and stock updates.
  4. 38. Database Normalization (1NF, 2NF, 3NF)Understand database normalization with a real e-commerce example: 1NF, 2NF and 3NF, why we split tables, and when analysts denormalize on purpose.

Module 9

SQL for Analysts

  1. 39. SQL Pivot: Rows to ColumnsPivot rows into columns in SQL with conditional aggregation and FILTER, and unpivot columns back into rows. Build month-by-category sales reports.
  2. 40. SQL Interview Questions for Data Analysts15 SQL interview questions data analysts are asked, solved on a real dataset: nth highest salary, duplicates, top N per group, MoM growth, retention.

Ready to test yourself?

Try real interview problems with instant answer checking, or learn SQL through IPL cricket.

Newsletter

Keep learning SQL

One email a week with SQL and analytics guides, new practice questions and cohort dates. No spam, unsubscribe anytime.