// 免費工具

SQL query generator

Pick a table, add columns, joins and conditions, and the SELECT statement writes itself with the identifier quoting and row-limit syntax of the engine you pick. A small sample schema (orders, customers, products, order_items) is preloaded to click through, or paste your own CREATE TABLE statements and build against those. The query is generated in your browser: nothing you paste or build is sent anywhere.

Jump to the generated SQL
Use your own schema

Paste CREATE TABLE statements (SQL Server, PostgreSQL, MySQL or SQLite DDL, including pg_dump -s 和 mysqldump --no-data output) and press Use this schema. The pickers then list your tables and columns, and your foreign keys drive the joins. Names you quoted in the DDL keep their case; unquoted names are folded the way PostgreSQL (lower case) and Oracle (upper case) store them.

欄

聯結

WHERE conditions

HAVING

ORDER BY

Generated SQL

SELECT "customers"."name",
       COUNT("orders"."id") AS "order_count"
FROM "orders"
INNER JOIN "customers" ON "orders"."customer_id" = "customers"."id"
WHERE "orders"."status" = 'shipped'
GROUP BY "customers"."name"
HAVING COUNT("orders"."id") > 5
ORDER BY "customers"."name" ASC
LIMIT 20

What the query generator builds

One SELECT statement, regenerated after every change: a select list with optional aliases and aggregates, joins that follow the schema's foreign keys, WHERE conditions, grouping with a HAVING filter, sorting and a row limit.

  • Columns and aggregates. Every column can carry COUNT, COUNT DISTINCT, SUM, AVG, MIN or MAX, and an alias. Turn on the GROUP BY checkbox and the non-aggregated columns move into a GROUP BY clause automatically.
  • Joins. INNER or LEFT joins with two ON pickers, preset to the foreign key between the joined table and a table already in the query. If a column, condition or sort mentions a table you never joined, the generator adds INNER JOINs along the shortest foreign-key chain to it (products from orders goes through order_items) and says so; a composite foreign key gets every column pair in its ON. A table that no foreign key reaches gets a warning instead.
  • Conditions. The usual comparison operators, plus LIKE, IN (comma-separated list), BETWEEN (comma-separated bounds) and IS NULL / IS NOT NULL. Numbers are written bare and everything else as a quoted string, with embedded quotes doubled; = NULL 變成 IS NULL, and on Oracle a date such as 2024-01-31 becomes DATE '2024-01-31', because a plain string is read through NLS_DATE_FORMAT. Combine rows with AND or OR; no parentheses are added, so AND binds tighter than OR, as in any SQL engine.
  • Row limits per engine. PostgreSQL, MySQL and SQLite get LIMIT/OFFSET. SQL Server gets TOP (n),或 OFFSET ... FETCH when you set an offset. Oracle gets FETCH FIRST n ROWS ONLY, which every release since 12c accepts.
  • Quoting per engine. [square brackets] 針對 SQL Server, "double quotes" for PostgreSQL, SQLite and Oracle, and `backticks` for MySQL, so a table named order will not explode on you. A name created without quotes is written the way the engine stored it: upper case on Oracle ("ORDERS"), lower case on PostgreSQL. Names your DDL quoted keep their exact case.
  • Your schema or the sample. orders, customers, products and order_items with their foreign keys are preloaded. Paste CREATE TABLE statements under Use your own schema and the pickers switch to your tables, columns and foreign keys; the DDL is read by the same parser as the ER diagram generator.

The same query, generated for each engine

The builder starts with this query in its PostgreSQL form. Switch the engine and only the parts that differ change: the quote characters and the way the row limit is written.

SQL Server: TOP and square brackets

SELECT TOP (20) [customers].[name],
       COUNT([orders].[id]) AS [order_count]
FROM [orders]
INNER JOIN [customers] ON [orders].[customer_id] = [customers].[id]
WHERE [orders].[status] = 'shipped'
GROUP BY [customers].[name]
HAVING COUNT([orders].[id]) > 5
ORDER BY [customers].[name] ASC

With an offset, SQL Server swaps TOP for the standard OFFSET n ROWS FETCH NEXT m ROWS ONLY, which requires an ORDER BY, so the generator adds ORDER BY (SELECT NULL) if you did not pick one. Oracle uses the same OFFSET/FETCH clause; Oracle 11g and older lack it, so on those releases rewrite a plain limit as a SELECT * FROM (...) WHERE ROWNUM <= n subquery. MySQL and SQLite only accept OFFSET after a LIMIT, so an offset without a limit is written as LIMIT 18446744073709551615 OFFSET n 和 LIMIT -1 OFFSET n.

What it does not do: the generator builds SELECT queries only. No INSERT, UPDATE or DELETE, no window functions, no UNION. Paste the result into your database's editor and let it check the types: the generator knows names and foreign keys, not column types.

Query generator FAQ

Is this query generator free?

Yes. It is free to use with no sign-up and no usage limits, and it works offline once the page has loaded.

Is my schema sent to a server?

No. The sample schema ships with the page, and DDL you paste is parsed by the page's own JavaScript. Your schema, aliases and values stay in your browser tab; the SQL is generated locally and never uploaded, logged or stored.

Can I use my own tables instead of the sample schema?

Yes. Open Use your own schema, paste CREATE TABLE statements (SQL Server, PostgreSQL, MySQL or SQLite DDL, including pg_dump -s and mysqldump --no-data output) and press Use this schema. The pickers then offer your tables and columns, and your foreign keys, including composite ones, drive the automatic joins.

Which SQL engines does it generate queries for?

SQL Server, PostgreSQL, MySQL, SQLite and Oracle. Each engine gets its own identifier quoting (square brackets, double quotes or backticks) and its own row-limit syntax: TOP or OFFSET/FETCH for SQL Server, LIMIT/OFFSET for PostgreSQL, MySQL and SQLite, and FETCH FIRST for Oracle.

Can it generate INSERT, UPDATE or DELETE statements?

No. The generator builds SELECT queries only: column lists, joins, grouping and row limits are where the engines differ most and where a builder saves typing. Check the result before running it either way.

Why are all identifiers quoted in the output?

Quoting every name with the engine's own quote character means a column called order or user never collides with a reserved word. The catch is that quoted names are case-sensitive in PostgreSQL and Oracle. PostgreSQL folds unquoted names to lower case and Oracle to upper case, so a table created as Orders without quotes is written "orders" for PostgreSQL and "ORDERS" for Oracle; a name the DDL quoted keeps its case.

Is the generated SQL guaranteed to be valid?

No. It assembles the clauses you chose into one SELECT and takes names and foreign keys from the schema, but it knows nothing about column types, so SUM over a text column is your call. Mixing aggregated and plain columns without the GROUP BY box ticked, or sorting a grouped query by a column that is not grouped, produces SQL most engines reject; the status line under the SQL warns about both.

// build them faster in the app

Writing queries by clicking? SQLly autocompletes them

A native SQL workbench for macOS, Windows and Linux with IntelliSense that knows your schema, guardrails for risky queries, and the formatter from our other tools built into the editor.