MySQL Practice Exercises

Build confidence writing queries with MySQL practice problems designed for MySQL 8.4. Start with selecting and filtering records, then explore joins, aggregate functions, and other SQL features. Your queries execute in a real MySQL database, and the trainer automatically checks the output against expected results using hidden data. Problems in this set: 324, free: 106.

Problems in this set: 324, free: 106

Start with a free problem

MySQL problems

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Zombie Sessions Lasting More Than a Day

    The platform team is looking for "zombie sessions" — sessions that last more than a day and were probably not closed properly. Find sessions whose duration is greater than 24 hours.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Users with Valid Email Addresses

    The data quality team is checking user email addresses before sending a campaign.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Products with Valid Serial Numbers

    The warehouse team is checking the quality of product serial number data. Find products whose entire serial_number matches the pattern SN- followed by exactly 4 digits, such as SN-1234.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Students Studying Three or More Subjects

    The academic office is reviewing students' workloads to find those studying several subjects. Each row in StudyPatterns represents one study session, recording a student, a subject, and a date.

  • EasyFree
    PostgreSQL · MySQL

    Fix Reversed Employee Sex Codes

    An import error reversed the employee sex codes in the Salary table. Change m to f and f to m. Update all rows in a single operation, without auxiliary tables or intermediate values.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Frequent Actor-Director Collaborations

    A casting agency is looking for established actor-director partnerships. Return the actor_id and director_id for each actor-director pair that has worked together at least 3 times.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Bank Customers with Balances Above 10000

    The bank is preparing a report on users with high account balances. An account's balance is the sum of all transactions for that account. Find users whose total account balance exceeds 10000.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Classes with at Least Five Students

    The academic administration wants to know which classes have enrolled enough students to start classes. Find all classes with 5 or more students. Return the class column.

  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Apple Pay and Other Payment Amounts

    Visa is analyzing its partnership with Apple Pay. For each merchant_id, calculate the total amount of transactions made through Apple Pay as apple_pay_amount and the total amount of transactions made…

    Visa
  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Signup Confirmation on the Next Day

    TikTok is analyzing new user behavior. Find users who confirmed their email (signup_action = 'Confirmed') via SMS on the calendar day immediately after signing up, not on the signup date itself.

    TikTok
  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Final Account Balances

    Calculate the final balance of each account from the transaction log. The transaction_type column can contain Deposit or Withdrawal. Return account_id and final_balance. Sort the result by account_id.

    PayPal
  • EasyFree
    PostgreSQL · MySQL · ClickHouse

    Concert Venue Types in Moscow

    A concert producer in Moscow is preparing a presentation about the types of venues that have hosted concerts in the city. Return all distinct venue types for concerts held in Moscow.

What you will practice

  • Retrieve and limit query results using SELECT and LIMIT
  • Handle missing values with the IFNULL function
  • Combine grouped values into strings using GROUP_CONCAT
  • Filter and transform dates using MySQL date functions
  • Work with joins and window functions in MySQL

Common mistakes

  1. 1. Trying to use FULL OUTER JOIN

    MySQL 8.4 does not support FULL OUTER JOIN directly. Copying a query that uses this operator from another SQL dialect will fail. Before choosing an alternative, decide whether you need matching rows, all records from one table, or unmatched records from both sides.

  2. 2. Expecting GROUP_CONCAT to sort automatically

    GROUP_CONCAT combines values into a string, but their order is not guaranteed unless you specify it. Two results can contain the same elements in different sequences. If order matters, define it inside the aggregate function and test groups containing several distinct values.

  3. 3. Replacing NULL without considering its meaning

    IFNULL replaces a NULL value with a chosen alternative. However, zero, an empty string, and missing data do not always mean the same thing. Replacing missing values before calculating an aggregate can change the metric. Decide when the substitution should happen and why.

  4. 4. Using LIMIT without ORDER BY

    LIMIT controls how many records are returned, not which ones rank highest or lowest. Without ORDER BY, MySQL does not guarantee a particular row order. Specify the sorting criteria first, and consider what should happen when multiple records have equal values.

Theory and courses

Frequently asked questions

Which version of MySQL do these exercises use?

The exercises in this collection support MySQL 8.4. Queries run in a real database, and results are automatically checked against expected output using hidden data. When adapting SQL from another database system, pay attention to differences in functions, joins, and date handling.

Is there a free way to practice MySQL?

Yes. Free MySQL problems: 106. After signing in, you can solve up to 3 new problems per day on the free plan. Premium exercises are visible in the list but require a subscription. Reference SQL solutions are not published.

Does MySQL 8.4 support window functions?

Yes. MySQL has supported window functions since version 8.0, so they are available in MySQL 8.4. They let you calculate ranks, running values, and other metrics across related rows without necessarily reducing each group to a single result row.

How is IFNULL different from WHERE?

IFNULL changes the value returned by an expression when that value is NULL. WHERE determines which rows belong in the result. Use a replacement when you want to keep the record with a fallback value, and a filter when records should be excluded.

How can I handle a full outer join in MySQL?

MySQL 8.4 has no native FULL OUTER JOIN operator. If you need matching and unmatched records from both tables, you must combine supported SQL operations to produce that result. Be careful with duplicates and determine whether each matching pair should appear once.