Skip to content
engineering workbench.by StudyPort Academy
Learning path
Foundations18 min

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

SQL Query Execution Order
ClausePurposeLogical Execution Order
FROM & JOINIdentifies target tables and joins rows together1st (determines dataset)
WHEREFilters individual rows based on boolean predicates2nd (discards non-matching rows)
GROUP BYCollapses rows into aggregate buckets3rd (groups remaining rows)
HAVINGFilters aggregate groups after calculation4th (discards groups)
SELECTProjects requested columns and evaluates expressions5th (shapes final output)
ORDER BY & LIMITSorts resulting rows and caps returned count6th (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.

    01Which clause is evaluated first during the logical execution of a SQL query?
    02What is the difference between WHERE and HAVING in SQL?

    Ready to call this one understood?

    Mark this lesson complete to earn 100 XP. You can always revisit it.

    Sign in to save progress
    Next lesson