SQL Fundamentals: SELECT, INSERT, UPDATE, DELETE
Understand the idea
How declarative SQL turns complex data filtering and aggregation into concise statements.
The idea
SQL (Structured Query Language) is a declarative language: you describe the data you want to find, and the database figures out the best way to get it. Unlike JavaScript where you write loops and manual array filters, SQL lets you ask for data directly.
When you send a SQL statement, the database parses your request, sends it to the , and runs the plan. A standard SELECT statement uses WHERE to filter rows, GROUP BY to calculate totals, and ORDER BY to sort the results.
Because SQL is declarative, the database can optimize behind the scenes-such as using an instead of checking every single row one by one.
What changes
| Clause | Purpose | Logical Execution Order |
|---|---|---|
| FROM & JOIN | Identifies target tables and joins rows together | 1st (determines dataset) |
| WHERE | Filters individual rows based on boolean predicates | 2nd (discards non-matching rows) |
| GROUP BY | Collapses rows into aggregate buckets | 3rd (groups remaining rows) |
| HAVING | Filters aggregate groups after calculation | 4th (discards groups) |
| SELECT | Projects requested columns and evaluates expressions | 5th (shapes final output) |
| ORDER BY & LIMIT | Sorts resulting rows and caps returned count | 6th (final presentation) |
The command
SELECT with aggregation and GROUP BY
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
QUERY VISUALIZER
Before the run · edit the code, then press Run to see what changes.
Source tables appear here when available; successful runs show their captured data.
Watch a query change the table
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
QUERY VISUALIZER
Before the run · edit the code, then press Run to see what changes.
Source tables appear here when available; successful runs show their captured data.
The mistake
Check the result
Run the example to see SQLite filter products over $3.00, group them into categories, and output aggregated count and average price rows.
Guided challenge
Build SQL filter predicate
Update the function to return a formatted SQL WHERE predicate string matching the minPrice and maxPrice parameters.
Build SQL filter predicate
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
EXPECTED RESULT
price >= 10 AND price <= 50
Hints 0/1
Use all hints or make 3 failed checks (0/3).
Free exploration
Change this example and run it again. Each run is a new process. Nothing is saved.
Your variation
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 100 XP. You can always revisit it.