UpSkill Sprint Consulting logo UpSkill Sprint Consulting
Open SQL lab

Power BI, Excel & SQL

Writing Your First SQL Query

Beginner Interactive 35 min SQL lab included

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, and LIMIT do.
  • Write a query that retrieves, filters, sorts, groups, and limits data.
  • Connect related tables using a key and a valid JOIN condition.
  • Distinguish row filtering with WHERE from group filtering with HAVING.
  • 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.

SELECT
Chooses the columns or calculations to display.
FROM
Identifies the table that supplies the starting rows.
WHERE
Filters individual rows before grouping or aggregation.
ORDER BY
Sorts the returned rows in ascending or descending order.
GROUP BY
Combines rows that share the same values so aggregates can be calculated.
HAVING
Filters grouped results after GROUP BY.
JOIN
Combines related rows from two or more tables.
LIMIT
Returns only a specified number of rows in SQLite, PostgreSQL, and MySQL.

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
customers.customer_id β†’ production_orders.customer_id   |   production_orders.order_id β†’ quality_tests.order_id

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

  1. SELECT
  2. FROM
  3. JOIN
  4. WHERE
  5. GROUP BY
  6. HAVING
  7. ORDER BY
  8. LIMIT

How it is logically resolved

  1. FROM and JOIN
  2. WHERE
  3. GROUP BY
  4. HAVING
  5. SELECT
  6. ORDER BY
  7. LIMIT
Memory aid: start with the question you want to display, identify where the data lives, narrow the rows, summarize if needed, then sort and limit the final result.

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.

Clause 1 of 8

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.

    Loading SQLite engine…
    query.sqlLine 1, column 1

    Press Control Enter or Command Enter to run the query. Press Tab to indent.

    Ctrl/Cmd + Enter to run

    Ready to learn

    The first query will run when the database finishes loading.

    Query result

    No query run
    Results will appear here.

    Guided 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

    MistakeWhy it failsCorrection
    Missing commaSQL reads two column names as one invalid expression.SELECT product, grade
    WHERE before FROMThe source table must appear before row filtering in the written syntax.FROM production_orders WHERE …
    Unquoted textSQL treats an unquoted word as a column name.WHERE status = 'Complete'
    Aggregate in WHEREWHERE runs before groups are calculated.Place aggregate conditions in HAVING.
    Join without ONThe database does not know how rows in the two tables correspond.ON p.customer_id = c.customer_id
    Ambiguous columnBoth joined tables contain a column with the same name.Qualify it: p.order_id.
    LIMIT before ORDER BYClauses are written in the wrong order.ORDER BY … LIMIT 5
    SQL Server TOP in SQLiteDifferent 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;
    Workplace rule: confirm the database platform before copying syntax from an example. The query logic may be correct even when one dialect-specific keyword must change.

    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.

    1. Which clause chooses the columns shown in the result?
    2. What is the main purpose of FROM?
    3. Which clause should filter orders whose status is 'Complete'?
    4. How do you sort quantity from highest to lowest?
    5. Which clause is needed to calculate SUM(quantity) for each production line?
    6. Which clause filters groups where SUM(quantity) is greater than 500?
    7. What does JOIN do?
    8. Which is a valid JOIN condition for orders and customers?
    9. Where should LIMIT 5 appear?
    10. Why is 'Complete' enclosed in quotation marks?

    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.

    References and further practice

    1. SQLite SELECT documentation
    2. SQLite expression documentation
    3. sql.js documentation
    4. Microsoft Transact-SQL SELECT documentation