/

/

Practice SQL Online: Free Exercises and Interactive Challenges

Content

Practice SQL Online: Free Exercises and Interactive Challenges

Practice SQL Online: Free Exercises and Interactive Challenges

Practice SQL Online: Free Exercises and Interactive Challenges

Practice SQL Online: Free Exercises and Interactive Challenges

SQL remains one of the most valuable skills in tech, data science, and business analytics. Whether you are preparing for a job interview, transitioning into a data role, or simply trying to query your company's database more effectively, the best way to get better is to practice SQL online. The good news is that you no longer need to install databases or configure servers. Dozens of free platforms let you write and run real SQL queries directly in your browser, with instant feedback on your results.

This guide covers the best free resources for SQL practice, walks you through real practice problems at every difficulty level, and shows you how to structure a learning path that actually sticks.

Why Practice SQL Online?

Reading SQL syntax from a textbook is one thing. Writing queries against real datasets and debugging your mistakes is something else entirely. Here is why practicing SQL in an interactive, online environment matters:

Hands-on learning beats passive reading. Studies in cognitive science consistently show that active recall and practice produce far deeper learning than simply reading documentation. When you write a query, hit run, and see whether your output matches the expected result, you are encoding that knowledge in a way that sticks.

No local setup required. Setting up PostgreSQL, MySQL, or SQL Server locally can be a frustrating barrier for beginners. Online SQL practice platforms give you a pre-loaded database, a query editor, and sample data, all inside your browser. You can start writing your first SELECT statement within seconds.

Instant feedback accelerates progress. The best platforms tell you immediately whether your query is correct, show you the expected output, and sometimes even explain where you went wrong. This tight feedback loop is what turns a slow learner into a fast one.

Interview preparation. SQL is one of the most commonly tested skills in data analyst, data engineer, and backend developer interviews. Practicing with timed challenges and ranked difficulty levels mirrors the actual interview experience.

Best Free Platforms to Practice SQL

Not all practice platforms are created equal. Some focus on guided tutorials, others on competitive problem-solving. Here are the best options available today, organized by what they do best.

SQLBolt

SQLBolt is one of the cleanest and most beginner-friendly SQL tutorials on the web. It walks you through SQL concepts one lesson at a time, with an interactive editor embedded directly into each page. Each lesson introduces a single concept, such as SELECT, filtering with WHERE, or using JOIN, and then asks you to solve two or three short exercises before moving on. Best for: absolute beginners who want a structured, linear introduction. Difficulty: beginner to low-intermediate.

W3Schools SQL Exercises

W3Schools provides a "Try It Yourself" editor that lets you run SQL against a sample database with tables like Customers, Orders, and Products. The reference documentation is extensive, and you can modify any example query to experiment on your own. Best for: quick reference and casual practice while learning new syntax. Difficulty: beginner.

HackerRank SQL

HackerRank offers a dedicated SQL domain with problems organized into categories: Basic Select, Advanced Select, Aggregation, Basic Join, Advanced Join, and Alternative Queries. Each problem has a difficulty rating (easy, medium, hard), test cases, and a discussion section where other users share their approaches. Best for: interview preparation and building a visible coding profile. Difficulty: beginner to advanced.

LeetCode Database Problems

LeetCode is famous for algorithm challenges, but its database section contains over 200 SQL problems drawn from real interview questions at major tech companies. Problems are tagged by topic (joins, subqueries, window functions) and difficulty. The premium tier unlocks more problems, but the free tier has plenty to work with. Best for: serious interview prep, especially for FAANG-level roles. Difficulty: intermediate to advanced.

Mode Analytics SQL Tutorial

Mode offers a complete SQL tutorial built around real-world analytics datasets. What sets it apart is that the datasets feel like actual business data, not toy examples. You work with event logs, user activity tables, and time-series data. The tutorial progresses from basic queries through window functions and performance tuning. Best for: aspiring data analysts who want to practice with realistic analytics scenarios. Difficulty: beginner to advanced.

SQLZoo

SQLZoo has been around for years and remains a solid resource. It features interactive exercises organized by topic, with a built-in query runner. The problems use well-known datasets like world country data, Nobel Prize winners, and movie databases. Some of the later exercises are genuinely challenging. Best for: learners who want varied datasets and progressively harder challenges. Difficulty: beginner to intermediate.

Codecademy SQL Course

Codecademy provides a guided, project-based SQL course where you learn by building something rather than just solving isolated problems. The free tier covers the fundamentals: creating tables, querying data, aggregate functions, and working with multiple tables. Best for: learners who prefer a structured curriculum with milestones. Difficulty: beginner.

Khan Academy Intro to SQL

Khan Academy offers a gentle, video-driven introduction to SQL that is particularly well-suited for people with no programming background at all. Each video lesson is followed by a coding challenge in the browser. The scope is narrower than other platforms, but the teaching quality is excellent. Best for: complete beginners and younger learners. Difficulty: beginner.

StrataScratch

StrataScratch specializes in real interview questions from companies like Amazon, Microsoft, Google, and Netflix. Each problem includes the company name, role, and difficulty. You can solve problems in SQL or Python, and compare your solution against others. Best for: targeted interview preparation with company-specific questions. Difficulty: intermediate to advanced.

SQL Practice Problems by Difficulty

Below are real SQL exercises you can work through right now. Each problem uses a simple schema that you can recreate on any practice platform. Assume the following tables exist:

-- employees table
-- id | name        | department  | salary | hire_date
-- 1  | Alice Chen  | Engineering | 95000  | 2020-03-15
-- 2  | Bob Park    | Marketing   | 72000  | 2019-07-22
-- 3  | Carol Diaz  | Engineering | 105000 | 2018-01-10
-- 4  | Dan Lee     | Sales       | 68000  | 2021-11-03
-- 5  | Eva Stone   | Marketing   | 78000  | 2020-06-18
-- 6  | Frank Kim   | Engineering | 112000 | 2017-09-25
-- 7  | Grace Wu    | Sales       | 71000  | 2022-02-14
-- 8  | Hank Roy    | Engineering | 98000  | 2021-04-30

-- orders table
-- id | employee_id | product     | amount  | order_date
-- 1  | 2           | Widget A    | 1500    | 2023-01-15
-- 2  | 4           | Widget B    | 2300    | 2023-02-20
-- 3  | 2           | Widget C    | 800     | 2023-03-10
-- 4  | 5           | Widget A    | 1500    | 2023-01-28
-- 5  | 7           | Widget B    | 2300    | 2023-04-05
-- 6  | 4           | Widget A    | 1500    | 2023-05-12
-- 7  | 2           | Widget B    | 2300    | 2023-06-01

Beginner: SELECT, WHERE, ORDER BY

Problem 1: Retrieve the names and salaries of all employees in the Engineering department, ordered by salary from highest to lowest.

SELECT name, salary
FROM employees
WHERE department = 'Engineering'
ORDER BY salary DESC;

Result: Frank Kim (112000), Carol Diaz (105000), Hank Roy (98000), Alice Chen (95000).

Problem 2: Find all employees who were hired after January 1, 2021.

SELECT name, department, hire_date
FROM employees
WHERE hire_date > '2021-01-01'
ORDER BY hire_date;

Result: Hank Roy (2021-04-30), Dan Lee (2021-11-03), Grace Wu (2022-02-14).

Problem 3: List all unique departments in the company, sorted alphabetically.

SELECT DISTINCT department
FROM employees
ORDER BY department;

Result: Engineering, Marketing, Sales.

Intermediate: JOIN, GROUP BY, HAVING

Problem 4: Show each employee's name alongside the total value of their orders. Include only employees who have placed at least one order.

SELECT e.name, SUM(o.amount) AS total_order_value
FROM employees e
INNER JOIN orders o ON e.id = o.employee_id
GROUP BY e.name
ORDER BY total_order_value DESC;

Result: Bob Park (4600), Dan Lee (3800), Grace Wu (2300), Eva Stone (1500).

Problem 5: Find departments where the average salary exceeds 80,000.

SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > 80000
ORDER BY avg_salary DESC;

Result: Engineering (102500).

Problem 6: List employees who have never placed an order.

SELECT e.name, e.department
FROM employees e
LEFT JOIN orders o ON e.id = o.employee_id
WHERE o.id IS NULL;

Result: Alice Chen, Carol Diaz, Frank Kim, Hank Roy.

Advanced: Window Functions, CTEs, and Subqueries

Problem 7: Rank employees within each department by salary, and show only the highest-paid employee per department.

WITH ranked AS (
    SELECT
        name,
        department,
        salary,
        RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dept_rank
    FROM employees
)
SELECT name, department, salary
FROM ranked
WHERE dept_rank = 1;

Result: Frank Kim (Engineering, 112000), Eva Stone (Marketing, 78000), Grace Wu (Sales, 71000).

Problem 8: Calculate a running total of order amounts over time, and show each order alongside the cumulative sum up to that point.

SELECT
    o.order_date,
    e.name AS employee_name,
    o.product,
    o.amount,
    SUM(o.amount) OVER (ORDER BY o.order_date ROWS UNBOUNDED PRECEDING) AS running_total
FROM orders o
INNER JOIN employees e ON o.employee_id = e.id
ORDER BY o.order_date;

Result: The running total starts at 1500 for the first order and accumulates to 12200 after the final order. This pattern is extremely common in financial reporting and analytics dashboards.

How to Structure Your SQL Learning Path

Random practice is better than no practice, but a structured approach will get you job-ready faster. Here is a realistic week-by-week plan:

Week 1 and 2: Foundations. Start with SQLBolt or Khan Academy. Master SELECT, WHERE, ORDER BY, LIMIT, and basic comparison operators. By the end of week two, you should be able to filter and sort data from a single table without hesitation.

Week 3 and 4: Aggregation and Grouping. Move to COUNT, SUM, AVG, MIN, MAX, GROUP BY, and HAVING. Practice on W3Schools and SQLZoo. These functions are the backbone of data analysis, and you will use them in virtually every real-world query.

Week 5 and 6: Joins. Learn INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN. Practice combining data from multiple tables on HackerRank. Understanding joins is the single biggest leap from beginner to intermediate SQL.

Week 7 and 8: Subqueries and CTEs. Start solving medium-difficulty problems on LeetCode and StrataScratch. Learn to use subqueries in WHERE clauses, FROM clauses, and SELECT lists. Get comfortable with Common Table Expressions (WITH clauses) for readability.

Week 9 and 10: Window Functions and Advanced Topics. Study ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, and SUM() OVER(). These are frequently tested in interviews and incredibly useful in production analytics. Use Mode Analytics for realistic practice scenarios.

Week 11 onward: Interview Simulation. Solve problems on LeetCode and StrataScratch under timed conditions. Aim for two to three problems per day. Review solutions from other users to learn alternative approaches.

Practice SQL with AI Assistance

One of the most effective ways to accelerate your SQL learning is to use AI-powered tools alongside your practice. Rather than replacing practice, AI can enhance it in several ways.

Generate example queries to study. When you encounter a concept you do not fully understand, such as self-joins or correlated subqueries, an AI tool can generate clear, annotated examples for you to read and then reproduce from memory.

Explain complex queries line by line. If you find a solution on a practice platform and cannot figure out how it works, you can paste it into a tool like AI2sql and get a plain-English breakdown of what each clause does and why it is structured that way.

Translate natural language to SQL. AI2sql lets you describe what you want in everyday language and generates the corresponding SQL query. This is valuable not as a shortcut, but as a learning aid: compare the AI-generated query to your own attempt, spot the differences, and understand why the AI's version might be more efficient or correct.

Validate your approach. After solving a problem, you can check whether your query handles edge cases such as NULL values, duplicate rows, or empty result sets. AI tools can point out potential issues you might overlook as a beginner.

The key is to use AI as a tutor, not a crutch. Write the query yourself first, then use AI to review, explain, or suggest improvements.

Frequently Asked Questions

How long does it take to learn SQL well enough for a job?

With consistent daily practice of 30 to 60 minutes, most people can reach a job-ready level of SQL proficiency in 8 to 12 weeks. This means being comfortable with joins, aggregations, subqueries, and basic window functions. The timeline depends on your starting point and how much practice you put in. Passive reading without hands-on SQL exercises will take significantly longer.

Which SQL dialect should I practice?

For learning purposes, the differences between MySQL, PostgreSQL, SQL Server, and SQLite are minor. The core syntax, covering SELECT, JOIN, GROUP BY, and subqueries, is virtually identical across all of them. Start with whatever dialect your practice platform uses. If you are targeting a specific job, check the job posting. PostgreSQL is the most common choice in startups and data engineering roles, while SQL Server is prevalent in enterprise environments.

Can I practice SQL on my phone?

Yes, though the experience is limited. W3Schools and SQLBolt work reasonably well in mobile browsers. There are also mobile apps like SQL Playground and Sololearn that offer SQL exercises optimized for smaller screens. However, for serious practice with complex queries, a laptop or desktop with a full keyboard is strongly recommended.

Are free SQL practice platforms enough, or do I need to pay for courses?

The free platforms listed in this guide are genuinely sufficient to go from zero to interview-ready. SQLBolt, HackerRank, LeetCode (free tier), SQLZoo, and Mode Analytics collectively cover every SQL concept you will encounter in a typical data role interview. Paid courses can offer more structured curricula and mentor support, but they are not necessary if you are disciplined about following a learning path like the one outlined above.

What should I do after finishing online exercises?

The best next step is to work with real data. Download a public dataset from sources like Kaggle, load it into a free cloud database such as ElephantSQL or Supabase, and start asking your own questions. Building a portfolio project where you clean, analyze, and present findings from a real dataset is far more impressive to employers than a high score on a practice platform.

Share this

More Articles

More Articles

More Articles