SQL Reference & Live Query Executor

Learn SQL syntax and run queries in your browser with sample database tables

SQL Query Editor
ℹ️ Note: SQL queries run entirely in your browser using SQLite (sql.js). For security, only SELECT queries are allowed. All data is sample data pre-loaded for practice.

Available Tables

Click "Run Query" to see data from these tables

Example Queries

Discover another handy tool from EditPDF.pro

Basic Queries

SELECT * FROM table_name;

Select all columns from a table

SELECT col1, col2 FROM table WHERE condition;

Select specific columns with filter

SELECT * FROM table ORDER BY col DESC;

Sort results descending

SELECT * FROM table LIMIT 10;

Limit number of results

Aggregations

SELECT COUNT(*) FROM table;

Count total rows

SELECT AVG(col) FROM table;

Calculate average

SELECT col, COUNT(*) FROM table GROUP BY col;

Group and count

SELECT SUM(col) FROM table WHERE condition;

Sum with condition

Joins

SELECT * FROM t1 JOIN t2 ON t1.id = t2.id;

Inner join (matching rows only)

SELECT * FROM t1 LEFT JOIN t2 ON t1.id = t2.id;

Left join (all rows from t1)

SELECT * FROM t1 RIGHT JOIN t2 ON t1.id = t2.id;

Right join (all rows from t2)

Filters & Conditions

WHERE col = 'value'

Exact match

WHERE col LIKE '%pattern%'

Pattern matching

WHERE col IN (1, 2, 3)

Multiple values

WHERE col BETWEEN 10 AND 20

Range condition

Subqueries

SELECT * FROM table WHERE col IN (SELECT col FROM other);

Subquery in WHERE clause

SELECT col, (SELECT COUNT(*) FROM t2 WHERE t2.id = t1.id) AS count FROM t1;

Subquery in SELECT clause

SELECT * FROM (SELECT * FROM table WHERE condition) AS subquery;

Subquery in FROM clause (derived table)

Window Functions

SELECT col, ROW_NUMBER() OVER (ORDER BY col) AS row_num FROM table;

Assign row numbers

SELECT col, RANK() OVER (PARTITION BY category ORDER BY value DESC) FROM table;

Rank within partitions

SELECT col, SUM(value) OVER (ORDER BY date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) FROM table;

Moving sum with window frame

Aggregate Functions

SELECT MIN(col), MAX(col) FROM table;

Minimum and maximum values

SELECT GROUP_CONCAT(col) FROM table;

Concatenate grouped values

SELECT col, COUNT(DISTINCT other_col) FROM table GROUP BY col;

Count distinct values