SQL Tutorial
SQL (Structured Query Language) is the language for asking questions of data stored in databases. Which products are almost out of stock? Who are the top 3 students in Math? How much did the store sell this week? With SQL, each of these is a short, readable command.
This free course has 21 lessons. The best part: every query runs live in your browser. Press Run this query, change the SQL, and see the results instantly. Nothing to install, and you can't break anything, because the sample database resets every time.
The sample database
Our examples use the database of Tindahan ni Aling Nena, a sari-sari store, with tables for products, customers, orders and order items, plus a small class record with students and grades. Lesson 2 shows every table.
What you'll be able to do
- Get exactly the data you need with
SELECTandWHERE - Sort, filter, search and summarize data
- Count, total and average with
GROUP BY - Combine tables with
JOIN - Add, change and delete data
- Design your own tables
No programming experience is needed. SQL is a great first "language" because it reads almost like English. After this course, the MySQL course shows how to use a real database server.
All lessons
Getting Started
- Introduction to SQL and DatabasesWhat a database is, what tables, rows and columns are, what SQL does, and your first query run live in the browser.
- The Sample Database — Tindahan ni Aling NenaMeet the tables used in this course — products, customers, orders, order_items, students and grades — and how they connect through ids.
- SQL SELECT — Choosing ColumnsRead data with SELECT and FROM, choose specific columns, compute new columns with math, and follow SQL's formatting rules.
Filtering & Sorting
- SQL WHERE — Filtering RowsChoose which rows to return with WHERE and comparison operators =, <>, >, <, >= and <=, using numbers and text.
- SQL AND, OR and NOTCombine several conditions in WHERE with AND, OR and NOT, and use parentheses to make complex filters work correctly.
- SQL ORDER BY — Sorting ResultsSort query results with ORDER BY in ascending (ASC) or descending (DESC) order, by several columns, and by computed values.
- SQL LIMIT and DISTINCTShow only the top results with LIMIT and OFFSET (like pages of results), and remove duplicate values with SELECT DISTINCT.
- SQL LIKE and Wildcards — Searching TextSearch for patterns in text with LIKE and the wildcards % and _, find names that start, end or contain certain letters, and build a simple search box query.
- SQL IN and BETWEENMatch a value against a list with IN, check ranges of numbers and dates with BETWEEN, and reverse them with NOT IN and NOT BETWEEN.
- SQL NULL Values — IS NULL, IS NOT NULL and COALESCEUnderstand NULL (a missing value), find it with IS NULL and IS NOT NULL, avoid the = NULL trap, and replace it with COALESCE or IFNULL.
Functions & Grouping
- SQL Aggregate Functions — COUNT, SUM, AVG, MIN, MAXSummarize data with COUNT, SUM, AVG, MIN and MAX — how many products, total stock, average grade, cheapest and most expensive item — plus ROUND.
- SQL GROUP BY and HAVINGSummarize data per group with GROUP BY — products per category, orders per customer, average per subject — and filter groups with HAVING.
- SQL Aliases, CASE and Useful FunctionsRename columns and tables with AS, label data with CASE WHEN (like DepEd grade descriptors), and use text, number and date functions such as UPPER, LENGTH, SUBSTR and ROUND.
Joins
- SQL JOIN — Combining Tables with INNER JOINCombine rows from two or more tables with INNER JOIN and ON — show customer names on orders, product names on order items, and compute sales.
- SQL LEFT JOIN, RIGHT JOIN and FULL JOINKeep all rows from one table with LEFT JOIN, find missing data such as customers with no orders and products never sold, and see how RIGHT and FULL joins compare.
- SQL Subqueries and UNIONUse a query inside another query — in WHERE with IN and comparisons, in FROM as a temporary table — check existence with EXISTS, and stack results with UNION.
Changing Data
- SQL INSERT INTO — Adding DataAdd new rows to a table with INSERT INTO ... VALUES, insert several rows at once, let the database fill in ids and defaults, and copy rows with INSERT ... SELECT.
- SQL UPDATE and DELETE — Changing and Removing DataChange existing rows with UPDATE ... SET ... WHERE, remove rows with DELETE, and avoid the classic disaster of forgetting WHERE.
Designing Tables
- SQL CREATE TABLE — Data Types and ConstraintsDesign your own tables with CREATE TABLE — choose data types, add PRIMARY KEY, NOT NULL, UNIQUE, DEFAULT, CHECK and FOREIGN KEY constraints.
- SQL ALTER TABLE, DROP, Indexes and ViewsChange a table's structure with ALTER TABLE, delete tables with DROP, speed up searches with indexes, and save useful queries as views.
- SQL Final Project — Sales Reports for a Sari-Sari StoreUse everything you learned to answer real business questions for Tindahan ni Aling Nena — sales per day, best sellers, top customers, utang list and restock alerts.