Xerobit

SQL Query Builder for SELECT Statements

This sql query builder lets you construct SELECT statements by filling in columns, tables, joins and conditions. A hand-written tokenizer parses and reformats the result so it is easy to read. Everything runs in your browser and nothing is uploaded to any server.

One join clause per line (JOIN, LEFT JOIN, etc.).

Generated SQL

SELECT *
FROM users;

How to use the sql query builder

  1. Enter the columns you want to retrieve, or type * for all columns.
  2. Provide the main table name. This field is required to build the query.
  3. Add optional clauses like joins, WHERE conditions, GROUP BY and ORDER BY.
  4. Set limit and offset numbers if you need pagination.
  5. The formatted SQL appears instantly as you type. Copy it directly into your database client.

How the SQL query builder works

This tool assembles a SELECT statement from the fields you provide. It starts with SELECT followed by your column list, then FROM and the table name. Each additional clause you fill in appends the corresponding SQL keyword and expression.

For example, if you enter id, name as columns, users as the table, age > 18 as the WHERE condition and 10 as the limit, the builder produces:

SELECT id, name FROM users WHERE age > 18 LIMIT 10;

The raw string is then passed through a hand-written tokenizer that splits it into keywords, identifiers, strings, numbers, operators and comments. The formatter uses those tokens to insert line breaks before major clauses, making the output readable without changing its meaning.

Tokenizer details and limits

The built-in tokenizer handles standard SQL constructs: single-quoted strings with doubled-quote escaping ('it''s'), double-quoted identifiers ("my column"), backtick-quoted identifiers, numeric literals including decimals, two-character operators like <= and !=, line comments starting with -- and block comments between /* and */.

It does not attempt full dialect parsing. Dialect-specific syntax such as MySQL's /*! ... */ conditional comments, PostgreSQL dollar-quoted strings ($$body$$), T-SQL bracket identifiers ([column]) or Oracle hint comments are treated as generic tokens. The formatter will preserve them but may not place line breaks around them perfectly. If you need strict validation, use a dedicated sql validator instead.

Common SELECT clauses reference

The following table summarizes the clauses this sql query builder supports and when to use each one.

ClausePurposeExample
SELECTColumns or expressions to returnid, name, COUNT(*)
FROMSource table or viewusers u
JOINCombine rows from another tableLEFT JOIN orders o ON u.id = o.uid
WHEREFilter rows before groupingstatus = 'active'
GROUP BYAggregate rows by column valuesdepartment_id
HAVINGFilter groups after aggregationCOUNT(*) > 5
ORDER BYSort the final result setcreated_at DESC
LIMIT / OFFSETRestrict row count and paginateLIMIT 20 OFFSET 40

Avoiding common mistakes

A frequent error is placing aggregate functions like COUNT() or SUM() in the WHERE clause. Aggregates must be filtered in the HAVING clause after GROUP BY. Another mistake is omitting table aliases when joining tables that share column names, which causes ambiguous-column errors in most databases.

String literals require single quotes, while identifiers with spaces or reserved words need double quotes or backticks depending on your database. Mixing these up is a common source of syntax errors. Also remember that LIMIT and OFFSET syntax varies: MySQL and PostgreSQL support LIMIT n OFFSET m, while SQL Server uses OFFSET m ROWS FETCH NEXT n ROWS ONLY. This builder outputs the LIMIT/OFFSET form.

Worked examples

ExampleInputResult
All columns from usersColumns: *; Table: usersSELECT * / FROM users;
Filtered and sortedColumns: id, name, email; Table: customers; WHERE: status = 'active'; ORDER BY: name ASC; Limit: 50SELECT id, name, email / FROM customers / WHERE status = 'active' / ORDER BY name ASC / LIMIT 50;
Join with aggregationColumns: u.name, COUNT(o.id) AS order_count; Table: users u; Joins: LEFT JOIN orders o ON u.id = o.user_id; WHERE: u.active = 1; GROUP BY: u.name; HAVING: COUNT(o.id) > 0; ORDER BY: order_count DESC; Limit: 10SELECT u.name, COUNT(o.id) AS order_count / FROM users u / LEFT JOIN orders o ON u.id = o.user_id / WHERE u.active = 1 / GROUP BY u.name / HAVING COUNT(o.id) > 0 / ORDER BY order_count DESC / LIMIT 10;
PaginationColumns: id, title; Table: posts; WHERE: published = true; ORDER BY: created_at DESC; Limit: 20; Offset: 40SELECT id, title / FROM posts / WHERE published = true / ORDER BY created_at DESC / LIMIT 20 OFFSET 40;

FAQ

Does this sql query builder execute my query?

No. It only constructs and formats the SQL text. You must copy the output and run it in your own database client or application.

Which SQL dialects are supported?

The builder generates standard ANSI SQL SELECT statements with LIMIT and OFFSET syntax common to MySQL, PostgreSQL and SQLite. Dialect-specific features like TOP or window functions are not automatically added but can be typed manually into the fields.

Can I build INSERT, UPDATE or DELETE queries here?

This tool focuses exclusively on SELECT statements. For INSERT queries, use the dedicated sql insert generator or convert existing data with csv to sql insert.

Is my data sent to a server?

No. The entire sql query builder runs locally in your browser. Nothing you type is transmitted anywhere.

Why does the tokenizer matter?

The tokenizer breaks your raw input into meaningful pieces like keywords, strings and operators. This allows the formatter to add line breaks at the right places without splitting a quoted string or breaking an operator like <= into two lines.

How do I handle special characters in string values?

Use standard SQL escaping. In single-quoted strings, double the quote character: 'O''Brien'. The tokenizer recognizes this pattern and keeps it intact during formatting.