Start here
Lessons and reference
Look things up
Start here
SQL
Power Query
Data modeling
Power BI and DAX
Finance playbooks
Run queries
Build and check
Pick a database and tables, add joins, columns, filters and totals, and get the SQL for SQL Server or MariaDB, with a plain-English explanation and a live run.
-- Choose a start table in step 2.
Pick a database and a table. Examples are one click away.
Related tables come from the declared foreign keys. Filters run before totals.
The SQL builds as you click, so you can read how each choice changes it.
A query asks a database for rows. This builder lets you make that query by choosing from lists instead of typing it. You start with one table, add related tables through the links the database already declares, tick the columns you want, add totals and filters, and choose how to sort and how many rows to return.
Each choice updates the SQL on the right, with plain-English notes beside it. Turn on Teach me to see the SQL one clause at a time.
The SQL is written for the engine you pick. SQL Server uses square brackets around names, schema names such as classicmodels.orders, and TOP to limit rows. MariaDB uses backticks, plain table names and LIMIT. Press Copy to take the SQL to your own tool, or Run it to see up to 200 rows here. The sample logins are read-only, so the builder cannot change any data.
A join links two tables on matching columns, such as orders.customerNumber and customers.customerNumber. The builder offers only the joins the database declares as foreign keys. INNER keeps only matching rows. LEFT keeps every row from the table already in the query. ANTI keeps the rows with no match at all, such as customers with no payments. Use the table search on large databases.
The builder makes single SELECT statements. It does not write calculations such as price times quantity, so for a value that multiplies two columns, start from a recipe or write the SQL by hand. Filters work on rows, not on totals; a condition on a total would need a HAVING clause, which this version does not add. Results on this page show at most 200 rows, and the sample caps any query at 500 rows.
The join list comes from the foreign keys declared in the database. Those keys record which columns refer to which table, so the join is correct by design. Joining on columns that are not keys is possible in SQL, but it is the kind of join that duplicates rows by accident.
ANTI keeps the rows from the first table that have no matching row in the second. The SQL uses NOT EXISTS for this. It adds no columns from the second table, so it works as a filter. Use it for questions such as "which customers have never placed an order".
Check the rows before the total. When a join reaches a table with several matching rows, each row of the first table appears once per match. A total of a column from the first table then counts those rows more than once. Total a column from the table with one row per event, such as payments, or group by the key you need.
More tools: all tools · function reference · guides