MySQL Online Compiler

Write and run MySQL queries online on a real MySQL 8.4 server. Sample databases, a schema view and results as tables. Free, no sign-up.

247 total executions (247 this month)
Embed

Press Run SQL to see the results here.

Test your SQL with quizzes

Short quizzes with code to read and run: answer, see the explanation, and earn XP and badges.

All SQL quizzes
Easy SQL Basics

SELECT & WHERE

Pick the columns you want and keep only the rows that match a condition.

What this quiz covers
  • Choosing columns with SELECT and SELECT *
  • Filtering rows with WHERE and comparison operators
  • Combining conditions with AND, OR and parentheses
#select#filtering
10 questions · ~5 min · 1 play Start
Easy SQL Basics

ORDER BY & LIMIT

Sort query results and keep only the first few rows.

What this quiz covers
  • Sorting with ORDER BY, ASC and DESC
  • Breaking ties with a second sort column
  • Keeping the first rows with LIMIT and skipping rows with OFFSET
#sorting#select
10 questions · ~5 min Start
Easy SQL Basics

DISTINCT

Remove duplicate rows from a result and count unique values.

What this quiz covers
  • Removing duplicate rows with SELECT DISTINCT
  • DISTINCT applies to the whole row, not one column
  • Counting unique values with COUNT(DISTINCT column)
#select#duplicates
10 questions · ~5 min Start
Easy SQL Basics

LIKE, IN & BETWEEN

Filter rows with text patterns, lists of values and ranges.

What this quiz covers
  • Pattern matching with LIKE, % and _
  • Case sensitivity of LIKE in SQLite, MySQL and PostgreSQL
  • Checking a list of values with IN and NOT IN
#filtering#patterns
10 questions · ~5 min Start
Medium SQL Basics

NULL Values

Learn how SQL treats missing values in comparisons, calculations and filters.

What this quiz covers
  • Why = NULL never matches and IS NULL does
  • NULL in arithmetic and comparisons like <>
  • Replacing missing values with COALESCE
#null#filtering
10 questions · ~6 min · 1 play Start
Easy Aggregates & GROUP BY

COUNT, SUM, AVG, MIN & MAX

Turn many rows into one number with the five core aggregate functions.

What this quiz covers
  • Counting rows with COUNT(*)
  • Totals and averages with SUM and AVG
  • MIN and MAX on numbers and text
#aggregates#select
10 questions · ~5 min Start
Medium Aggregates & GROUP BY

GROUP BY

Split rows into groups and calculate a total, count or average for each one.

What this quiz covers
  • One result row per group with GROUP BY
  • Aggregates per group like SUM, COUNT and AVG
  • Grouping by more than one column
#group-by#aggregates
10 questions · ~6 min Start
Medium Aggregates & GROUP BY

HAVING

Filter groups by their totals, counts or averages after GROUP BY.

What this quiz covers
  • Filtering groups with HAVING
  • WHERE (rows, before grouping) vs HAVING (groups, after)
  • Using WHERE and HAVING in the same query
#having#group-by
10 questions · ~6 min Start

How to run MySQL online

  1. Start from a sample database (Employees or Shop) or an empty one, and look at its tables on the Schema tab.
  2. Write your queries and press Run SQL or Ctrl + Enter. Each statement gets its own result table; select part of the code to run only that.
  3. Every MySQL run starts from the sample database and runs the whole editor, so keep your CREATE TABLE and INSERT statements there.
  4. Export any result as CSV, or press Share to copy a link with your queries.
  5. Stuck on a query? Generate writes SQL from a description, Explain walks through your query, Fix Code repairs errors and Optimize makes a query faster and clearer.

SQLite, PostgreSQL or MySQL?

SQLitePostgreSQLMySQL
Best forLearning SQL, quick tests, interviewsPractising the SQL of a real server: window functions, JSON, strict typesPractising MySQL itself: AUTO_INCREMENT, LIMIT, procedures
Start timeInstantA few seconds on the first run (it downloads about 3 MB)Instant (it runs on our server)
TypesFlexible: any value fits any columnStrict: INTEGER, NUMERIC, DATE, JSONB and moreMySQL types: INT, VARCHAR, DECIMAL, DATETIME, JSON
Runs onYour browser, with no account and no serverOur MySQL 8.4 server, in a private database deleted after each run

Prefer a database that runs in your browser? The SQL Online Compiler has SQLite and PostgreSQL too.

Good to know

  • It runs on MySQL 8.4: AUTO_INCREMENT, backtick quotes, LIMIT, SHOW TABLES and DESCRIBE work as they are.
  • Stored procedures and triggers work with DELIMITER //, as in the mysql client.
  • A run can take up to 10 seconds and change up to 50,000 rows; each result shows its first 1,000 rows.
  • Each run uses a private database that is deleted right after; your SQL stays in this browser.
  • Import a .sql or .csv file: it goes into the editor and runs with it.
  • Switch Engine to SQLite or PostgreSQL to try the same query on another database.

MySQL queries to try

  • Auto-increment table: CREATE TABLE notes (id INT AUTO_INCREMENT PRIMARY KEY, body VARCHAR(200));
  • Top rows: SELECT name, salary FROM employees ORDER BY salary DESC LIMIT 3;
  • One list per group: SELECT department_id, GROUP_CONCAT(name SEPARATOR ', ') FROM employees GROUP BY department_id;
  • Format a date: SELECT name, DATE_FORMAT(hired_on, '%M %Y') FROM employees;
  • Look at the tables: SHOW TABLES; DESCRIBE employees;

Frequently asked questions

Is this a real MySQL server?

Yes. Your queries run on MySQL 8.4, so MySQL syntax works as it is: AUTO_INCREMENT, backtick quotes, LIMIT, SHOW TABLES, DESCRIBE, GROUP_CONCAT, DATE_FORMAT, stored procedures and triggers.

Are my tables kept?

Each run gets a fresh, private database that is deleted right after, so nobody else can see your tables. Your SQL is kept in this browser.

Why are my tables gone on the next run?

Every run starts from the sample database and runs everything in the editor. Keep your CREATE TABLE and INSERT statements in the editor; imported files are added there too.

What are the limits?

A run can take up to 10 seconds and insert, update or delete up to 50,000 rows, and each result shows up to 1,000 rows. That is plenty for learning, homework and interview practice.

Can I write stored procedures and triggers?

Yes. Use DELIMITER // and end the procedure with //, as in the mysql command-line client. CALL runs it and shows its results.

Is it free?

Yes. The MySQL editor, the sample databases and the CSV export are free and need no account.