Developer Tools

SQL Query Builder

Assemble a SELECT statement piece by piece. Add columns, joins, conditions, group filters and sort order in a form, and the SQL is written for you as you go, with correct grouping, bracketed AND/OR logic and the right syntax for your database.

  • Runs in your browser
  • No sign-up
  • Free to use
Columns (SELECT)

No columns means SELECT *. Columns with a function are aggregated; the others are grouped automatically.

Joins
Conditions (WHERE)

For IN, separate values with commas. For BETWEEN, enter two values separated by a comma.

Group filter (HAVING)
Sort (ORDER BY)
Output

    The query is assembled in your browser as text. Nothing is executed and no database is contacted.

    How to use SQL Query Builder

    1. Enter the table and choose your database.
    2. Add the columns you want, with a function such as COUNT or SUM where needed.
    3. Add joins, conditions and sort order; set a limit.
    4. Read the notes, then copy or download the query.

    SQL Query Builder features

    Clause-by-clause form

    SELECT, JOIN, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT, each with its own rows.

    Automatic GROUP BY

    When you mix plain and aggregated columns, the grouping is added correctly.

    AND / OR made explicit

    Brackets are added so that the result reflects how the database will evaluate mixed conditions.

    Full operator set

    Comparison, LIKE, IN, BETWEEN and NULL checks, with validation of the values each one needs.

    Dialect-aware

    LIMIT … OFFSET or TOP and OFFSET … FETCH, and the identifier quoting of MySQL, PostgreSQL, SQLite and SQL Server.

    Placeholders

    Values are written as ?, $1 or @p1 with a parameter list, ready for a prepared statement.

    When to use SQL Query Builder

    • Putting together a report query with joins and totals.
    • Learning how the clauses of a SELECT statement fit together.
    • Translating a query between database systems.
    • Preparing a parameterised query to paste into application code.

    SQL Query Builder FAQ

    How is this different from the SQL Query Generator?

    The generator produces complete statements for named tasks, including INSERT, UPDATE and CREATE TABLE. The builder concentrates on SELECT and gives you control over every clause, with any number of columns, joins, conditions and sort keys.

    Why was GROUP BY added to my query?

    SQL requires that every selected column is either inside an aggregate function, such as SUM, or listed in GROUP BY. When you select customer_id together with COUNT(*), the query only makes sense as “one row per customer_id”, so the builder groups by it.

    What is the difference between WHERE and HAVING?

    WHERE filters individual rows before grouping. HAVING filters the groups afterwards and can therefore use aggregate values. “Orders that are paid” belongs in WHERE; “customers whose total is over 1000” belongs in HAVING.

    How are AND and OR combined?

    AND has higher precedence than OR. A list such as A AND B OR C means (A AND B) OR C. The builder groups consecutive AND conditions in brackets so that what you read matches what the database does.

    Can I use table aliases or expressions?

    Columns can be written as table.column, and each selected column can have an alias. Free-form expressions are not accepted in the name fields, because the builder validates and quotes identifiers. Add expressions to the generated SQL by hand.

    Does it check my table and column names?

    No. Nothing is connected to a database. Names are used as you type them and quoted where needed. Misspelled names will be reported by your database when you run the query.

    How a SELECT statement is put together

    A SELECT statement is written in one order and evaluated in another, and knowing the second order explains most of its rules. The database starts with FROM and the joins, which produce the full set of candidate rows. WHERE then discards rows. GROUP BY collapses the rest into groups, and HAVING discards groups. Only then is the SELECT list computed, followed by ORDER BY and finally the row limit.

    That sequence is why an alias defined in the SELECT list can be used in ORDER BY but not in WHERE: at the time WHERE runs, the alias does not exist yet. It is why aggregate conditions go in HAVING. And it is why limiting rows without sorting gives arbitrary results: the limit is applied to whatever order the rows happen to be in.

    Joins deserve particular attention. An INNER JOIN keeps only pairs of rows that match, so an order without a customer disappears from the result. A LEFT JOIN keeps every row of the first table and fills the columns of the second with NULL where nothing matches. Putting a condition on the second table in WHERE silently turns a LEFT JOIN back into an inner one, since NULL fails the comparison. Qualifying every column with its table name avoids ambiguity when both tables have an id column.

    A builder is a good way to get the structure right and to see how each choice changes the statement. Real queries often grow beyond it, with subqueries, expressions, window functions and common table expressions. The generated SQL is plain text and a sound starting point: copy it into your editor, extend it, and run it against test data before it goes anywhere near production.

    Other useful tools