Loops and Iteration
LockedLesson 5 of 25 · Syntax · Easy
Finish these first:Conditionals and Branching →Or pass the tests below to unlock it now.
The big idea
In other languages, you write a for loop to step through items one by one. In SQL, the database loops through every row in a table automatically!
Think of it like this: Think of SQL like telling a helper 'count every folder in this drawer' — instead of writing a manual loop, the database walks through every row for you.
Read the lesson
In other languages, you write a for loop to step through items one by one. In SQL, the database loops through every row in a table automatically!
For example, COUNT(*) visits every row in a table and tells you how many rows there are:
SELECT COUNT(*) FROM students;
You already have a sample table called employees ready in memory — use SELECT COUNT(*) FROM employees; to count all of its rows in one line.
Quick check
What does `SELECT COUNT(*) FROM employees;` calculate?
Your challenge
Count how many people are in the employees table (type SELECT COUNT(*) FROM employees;).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.loops (90% overlap). Iteration: for-of in JS, range-for in C++, single 'for' keyword in Go, Iterator/for-in in Rust.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Loops and Iteration.
Learn this first
- Conditionals and BranchingNot yet