Power BI, Excel & SQL
Writing Your First SQL Query
Learn the eight clauses that form most everyday SQL queries. Write real code against a manufacturing database, see the result immediately, and receive a plain-language explanation when something goes wrong.
Why this matters: SQL lets you answer business and engineering questions directly from stored data instead of waiting for someone else to build every report.
Learning objectives
- Explain what
SELECT,FROM,WHERE,ORDER BY,GROUP BY,HAVING,JOIN, andLIMITdo. - Write a query that retrieves, filters, sorts, groups, and limits data.
- Connect related tables using a key and a valid
JOINcondition. - Distinguish row filtering with
WHEREfrom group filtering withHAVING. - Read a database schema and choose valid table and column names.
- Diagnose and correct common SQL syntax and logic errors.
The eight clauses you will use
A clause is a section of a SQL statement with a specific job. Select any row below to load its example into the live lab.
GROUP BY.Use-case scenario: production and quality reporting
You are supporting a manufacturing operation. Leaders want to know what was produced, which customers received it, and whether quality tests passed. The lesson database contains three connected tables.
production_orders
- order_id πINTEGER
- customer_idINTEGER
- order_dateTEXT
- productTEXT
- gradeTEXT
- lineTEXT
- quantityINTEGER
- statusTEXT
- scrap_tonnesREAL
quality_tests
- test_id πINTEGER
- order_idINTEGER
- test_typeTEXT
- result_valueREAL
- unitTEXT
- test_statusTEXT
- test_dateTEXT
customers
- customer_id πINTEGER
- customer_nameTEXT
- regionTEXT
- industryTEXT
Written order versus logical processing order
You write the clauses in one order, but the database logically resolves them in another. This explains why a table must be identified before its rows can be filtered.
How you write the query
SELECTFROMJOINWHEREGROUP BYHAVINGORDER BYLIMIT
How it is logically resolved
FROMandJOINWHEREGROUP BYHAVINGSELECTORDER BYLIMIT
Learn one SQL clause at a time
Choose one clause from the dropdown. The lesson will show only that clause, explain it in plain language, and give you one focused practice task before you move on.
Current clause
SELECT
Choose what appears in the result
What this clause does
How to use it
Beginner tip
Your focused practice
Example query
The practice button opens the live laboratory with a starter query. Complete the missing part, run the query, and use the friendly error coach when needed.
Live SQL laboratory
Edit the query and run it. The database exists only in your browser and resets when the page is reloaded. Only read-only queries are permitted.
Press Control Enter or Command Enter to run the query. Press Tab to indent.
Query result
No query runGuided practice sequence
The lab contains nine challenges. Work through them in order or jump directly to the skill you want to practise.
Common mistakes and how to correct them
| Mistake | Why it fails | Correction |
|---|---|---|
| Missing comma | SQL reads two column names as one invalid expression. | SELECT product, grade |
WHERE before FROM | The source table must appear before row filtering in the written syntax. | FROM production_orders WHERE β¦ |
| Unquoted text | SQL treats an unquoted word as a column name. | WHERE status = 'Complete' |
Aggregate in WHERE | WHERE runs before groups are calculated. | Place aggregate conditions in HAVING. |
Join without ON | The database does not know how rows in the two tables correspond. | ON p.customer_id = c.customer_id |
| Ambiguous column | Both joined tables contain a column with the same name. | Qualify it: p.order_id. |
LIMIT before ORDER BY | Clauses are written in the wrong order. | ORDER BY β¦ LIMIT 5 |
SQL Server TOP in SQLite | Different database systems use different dialects. | Use LIMIT in this lab. |
SQL dialect note: LIMIT versus TOP
The core ideas are portable, but some keywords differ by database platform. This lesson runs SQLite in your browser.
SQLite, PostgreSQL, and MySQL
SELECT product, quantity FROM production_orders ORDER BY quantity DESC LIMIT 5;
SQL Server
SELECT TOP 5 product, quantity FROM production_orders ORDER BY quantity DESC;
Final practical challenge
Management question: Which production lines completed more than two orders, what total quantity did each line produce, and which three lines had the highest completed quantity?
Your query must use SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT. Use the aliases completed_orders and total_quantity.
Practice quiz
Complete the quiz after using the SQL lab. Your best score can be saved by the UpSkillSprint lesson-progress system when you are signed in.
Your score: 0 out of 10.
Summary
- SELECT chooses the output and FROM identifies the source table.
- WHERE filters rows before grouping; HAVING filters groups after aggregation.
- GROUP BY creates categories for aggregate functions such as SUM and COUNT.
- JOIN connects tables through a valid key relationship stated in an ON condition.
- ORDER BY defines result order, and LIMIT restricts the number of returned rows in this SQLite lab.
- SQL errors are diagnostic clues: identify the clause, table, column, or value the database could not interpret, then correct one issue at a time.