Downloads

Visual SQL query builder

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.

7stepstable, join, columns, totals, filters, sort, limit
Realforeign keysjoins follow the declared keys
1. Database
2. Start table

3. Add a related table

Only tables linked to a table already in your query by a declared foreign key are listed.

    4. Columns to show

    Tick columns in the order you want them. Leave everything unticked to show all columns.

    5. Totals

    A total works out one number for each group. Any column ticked in step 4 becomes a group.

      6. Filters

      A filter keeps only the rows that pass it. Filters run before totals are worked out.

        7. Sort and limit

        SQL

        -- Choose a start table in step 2.

        In plain English

          Run it

          The three join types in this builder

          AB
          INNER Matching rows onlyCustomers who have orders. A customer with no orders disappears.
          AB
          LEFT Keep every row on the leftAll customers, with their orders when they have any. No orders shows blanks.
          AB
          ANTI Rows with no matchCustomers who have never ordered. This is a LEFT join that keeps only the blanks.

          How it works

          1. Choose a start table

            Pick a database and a table. Examples are one click away.

          2. Add joins, columns and totals

            Related tables come from the declared foreign keys. Filters run before totals.

          3. Run or copy

            The SQL builds as you click, so you can read how each choice changes it.

          What the builder does

          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.

          How the joins work

          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.

          Limits to know about

          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.

          Frequently asked questions

          Why can I only join tables that are related?

          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.

          What does the ANTI join do?

          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".

          Why does my total look wrong?

          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