Country or region and language

    Choose your country or region and your language.

    Suggested for you

      All countries and regions

        Choose your character

        It shows in the top bar and on your profile. Change it any time.

        Where to practice SQL

        Choose where to practice SQL by your goal, then run a small PostgreSQL exercise to check results, spot missing values, and plan your next practice session.

        A person practicing on a laptop in a quiet workspace

        If you're choosing where to practice SQL, use a hands-on learning site for guided feedback, a coding challenge platform for independent problem solving, or your own database for control over the data. Choose a setting that supports your SQL dialect and lets you check returned results, not just whether a query runs. Start with the small PostgreSQL exercise below to test your choice.

        Places to practice SQL

        The best place to practice SQL depends on whether you need an explanation, an independent task, or control over your practice data. SQL is the language you use to retrieve and change data in relational databases, which organize data into tables.

        The Work Gym is a hands-on practice site, HackerRank is a coding challenge platform, and W3Schools is an educational website. Those categories give you starting points, but a useful selection test is more specific: can you write a query, predict its result, inspect the output, and correct a mistake?

        For example, a query can run successfully while counting the wrong thing. A database accepts valid instructions; it doesn't know whether your business question was about products, recorded quantities, or units in stock. Your practice setting should help you notice that difference.

        Practice formats and selection criteria

        Choose a practice format by the work you'll do yourself and the feedback you'll need afterward. Reading a solution can explain an idea, but writing and checking a query tests whether you can apply the idea.

        Practice formats and your checking responsibility
        FormatUseful learning taskYour checking responsibilitySelection criterion
        Hands-on practice with feedbackWrite a query and revise an errorExplain why the corrected result is rightFeedback identifies the mistake rather than only rejecting the answer
        Coding challengesSolve a task without following a demonstrationCheck assumptions and consider unusual inputsTask wording and expected output are clear
        Video coursesObserve a workflow, then reproduce itPause and write the query before seeing the solutionExamples can be run in your chosen environment
        BooksWork through concepts and exercisesCompare your reasoning with the provided explanationThe examples identify their database dialect
        Free documentationCheck exact syntax and function behaviorBuild a small example with a predictable resultThe documentation matches your database and version

        For guided practice, consider the SQL course on The Work Gym. The site provides practice in working copies of tools in the browser, with automatic checking and a hint that names the mistake. The first unit of every course is free without an account.

        When you're ready to write a query yourself, try Practice: query a table.

        Check the dialect before choosing an environment. A dialect is a database's version of SQL, including its supported syntax and functions. The worked example uses PostgreSQL. If you're preparing for work with Oracle Database, use Oracle's documentation and an environment that explicitly supports Oracle SQL rather than assuming every example transfers unchanged.

        Practice what this post teaches

        A portable inventory exercise

        Use a small inventory count to test whether your chosen environment lets you run a query, inspect the output, and revise the data. The exercise uses temporary data inside a single PostgreSQL statement, so you don't need to create a permanent table.

        The fictional inventory has a product identifier called a SKU and a stock quantity for each product. NULL means a missing or unknown value, not zero. A common table expression gives a query result a temporary name within one statement; here, WITH names the inventory data, and VALUES supplies its rows.

        First, run only the baseline statement and compare its output with the expected baseline. Before running the variation, change only product C's stock quantity from NULL to 5 in the VALUES list. Keep the three counting expressions unchanged; the second statement below shows the exact revised query.

        -- Fictional exercise, PostgreSQL.
        -- Goal: count all products, known quantities, and missing quantities.
        -- Starting data: A has 10 units, B has 0 units, C is unknown.
        -- Model: products = COUNT(*).
        -- Model: known quantities = COUNT(stock_qty).
        -- Model: missing quantities = COUNT(*) - COUNT(stock_qty).
        
        WITH inventory(sku, stock_qty) AS (
          VALUES ('A', 10), ('B', 0), ('C', NULL)
        )
        SELECT COUNT(*) AS products,
               COUNT(stock_qty) AS known_quantities,
               COUNT(*) - COUNT(stock_qty) AS missing_quantities
        FROM inventory;
        
        -- Expected baseline:
        -- products | known_quantities | missing_quantities
        --        3 |                2 |                  1
        
        -- Variation: change only C's quantity from NULL to 5.
        WITH inventory(sku, stock_qty) AS (
          VALUES ('A', 10), ('B', 0), ('C', 5)
        )
        SELECT COUNT(*) AS products,
               COUNT(stock_qty) AS known_quantities,
               COUNT(*) - COUNT(stock_qty) AS missing_quantities
        FROM inventory;
        
        -- Expected variation:
        -- products | known_quantities | missing_quantities
        --        3 |                3 |                  0

        The first count includes every row, so the baseline has three products. The column count includes only non-NULL stock quantities, so it counts A and B but skips C. Subtracting the known-quantity count from the row count gives one missing quantity.

        Product B's zero is recorded information: the product has no units in stock. Product C's original NULL says the quantity isn't known. After you record five units for C, the inventory still has three products, but every product now has a known quantity.

        These results measure completeness, not total stock. The known-quantity result counts products with recorded quantities; it doesn't add their units. Naming the measure before writing SQL helps prevent a valid query from answering the wrong question.

        To continue working with summary results, try Practice: summarize data.

        Mistakes and useful feedback

        Useful feedback explains why your result differs from the target, rather than stopping at a successful execution message. Before reading the expected baseline again, explain aloud why the inventory has three products but only two known quantities.

        Another mistake is counting a nullable column when you intend to count rows. A nullable column is one that can contain NULL. In the baseline, counting stock quantities can't give the product count because C's quantity is missing.

        Use the variation as a second check. Recording C's quantity must increase the known count and reduce the missing count without changing the product count. If the product count changes, inspect whether you added a row, removed a row, or changed the counting expression.

        The limitation of this self-run exercise is that expected results don't automatically diagnose your mistake. You'll need to compare the data, query, and output yourself. A correct PostgreSQL result also doesn't establish that the same statement works unchanged in every SQL dialect.

        A repeatable practice session

        Build each practice session around one task that you can predict, run, and explain. Keep the dataset small enough to check by hand before moving to larger files.

        A practical practice loop

        • Write the task in plain language, including what each output column measures.
        • Predict the returned rows or summary values before running SQL.
        • Write the query without copying the worked solution.
        • Compare the actual output with your prediction and explain any difference.
        • Change one input value deliberately, predict the new output, and rerun the query.

        Choose your next topic from the mistake you found. Revisit missing values after a counting error, filtering after unexpected rows, or grouping after incorrect summaries. Grouping means dividing rows into categories before calculating a result for each category.

        Find practice data in course exercises, fictional datasets such as this inventory, or public datasets whose reuse terms you've checked. You don't need a large download to learn a precise distinction such as zero versus unknown.

        For interview preparation, save the task wording, query, expected output, and a short explanation together. A useful explanation names what you counted, how missing values affected the result, and why the variation changed only data completeness. Solving this exercise demonstrates that specific skill, not readiness for every SQL question.

        Common questions

        Where can I practice SQL as a beginner? Start with guided hands-on practice if you need mistakes explained, or use a PostgreSQL environment with small exercises and known results. The Work Gym offers SQL practice, and the first unit of every course is free without an account.

        Where can I find SQL data for practice? Use course datasets, create fictional rows, or choose public datasets after checking their reuse terms. Start with data you can inspect manually so you can distinguish a correct answer from a query that merely runs.

        How should I choose between guided SQL practice and coding challenges? Choose guided practice when you can't yet explain why a result is wrong and need feedback on the mistake. Choose independent challenges when you want to work from a task description without following a demonstrated solution.

        Can I use the same practice queries in PostgreSQL and Oracle Database? Some SQL concepts transfer, but syntax and supported features can differ. The example in this article uses PostgreSQL; for Oracle Database, check Oracle's documentation and test in an environment that explicitly supports Oracle SQL.

        Practice what this post teaches

        Your Work Gym account

        Save your progress and pick up on another device. Your browser's progress comes with you.

        or

        You can keep practicing without an account.

        Help and feedback

        Ask a question, tell us what is not working, or share an idea. We reply by email.

        What is it about?

        We use it only to reply to you.