About the SQL Query Builder
What is a SQL query builder?
A SQL query builder turns a form into a working SELECT statement. You describe your tables, tick the columns you want, add the joins and filters, and the SQL is written for you as you go. It saves the boilerplate when you're drafting something, and it's a decent way to see how the clauses fit together if you're still learning where HAVING goes.
This one is built for people who will actually run the query. Paste a CREATE TABLE statement out of your database and it reads the table and column names from it, types and constraints and all. Pick a database and the identifier quoting and pagination follow that dialect's rules. Ask for placeholders and you get a prepared statement with the values listed separately, ready for PDO or mysql2. And under the SQL there's a plain English sentence describing what you just built, which is the quickest way to catch a join you wired up backwards.
How to Use This Tool
- Describe your tables. Type
users(id, name, email), or paste your CREATE TABLE statements. Give a table a short alias if you want u.name instead of users.name in the output.
- Tick the columns. Leave it on all columns for a
SELECT *, or pick the ones you need. Add a count or a total if you're summarizing.
- Join, filter, group. Connect a second table on a shared column, keep the rows you want, then group and filter the groups if you're aggregating.
- Sort and page. Choose a sort column and direction, and set how many rows to return and how many to skip.
- Read it back. Check the Reads as sentence under the query. If it doesn't describe what you meant, the query doesn't either.
- Take it away. Copy it as plain SQL, or as a PHP, Python or Node snippet with the parameters already bound.
Common Use Cases
A visual builder earns its keep in a few specific situations.
- Drafting a reporting query: Group by a column, count the rows in each group, and filter to the groups that matter, without three attempts at the
GROUP BY.
- Turning a schema dump into a query: Paste the
CREATE TABLE you already have open and start ticking columns.
- Writing a prepared statement: Switch values to placeholders, copy the PHP or Node snippet, and paste it in with the bindings in the right order.
- Learning where the clauses go: Add one piece at a time and watch both the SQL and the English description change.
- Checking a dialect difference: Flip between MySQL, PostgreSQL, SQL Server, SQLite and Oracle to see how quoting and paging change.
Got a query already? The SQL Formatter will tidy it up. Need the tables before the query? The SQL Table Generator writes the CREATE TABLE for you. Or browse all our free developer tools.
Frequently Asked Questions
What kinds of queries can it build?
SELECT statements, and quite involved ones. You get column selection and DISTINCT, five join types, a WHERE clause with every common operator, COUNT, SUM, AVG, MIN and MAX, GROUP BY with HAVING, multi-column ORDER BY, and LIMIT with OFFSET. It does not write INSERT, UPDATE, DELETE or schema changes, since reading data is where clicking beats typing and the others are usually quicker to write by hand.
Can I paste a CREATE TABLE statement?
Yes, that's the fastest way to start. Paste it exactly as your database printed it. Column types, defaults, and table constraints like PRIMARY KEY and FOREIGN KEY are skipped, backticks, double quotes and square brackets are all understood, comments are ignored, and you can paste several statements at once. A column genuinely named key still comes through as long as it's quoted the way your database quotes it.
Why does the database dropdown matter?
SQL is a standard that every database bends. Picking one gets the details right, mainly how identifiers are quoted, with backticks in MySQL, double quotes in PostgreSQL, SQLite and Oracle, and square brackets in SQL Server. Paging differs too. Most use LIMIT and OFFSET, while SQL Server and Oracle want OFFSET with FETCH NEXT. There's one more trap the tool handles quietly. MySQL and SQLite reject an OFFSET with no LIMIT in front of it, so if you skip rows without limiting them, a stand-in row count is added and explained in a note.
Can it produce a prepared statement?
Yes. Set Values to placeholders and every filter value comes out as ? or as a named marker like :p1, with the bindings listed in order. Then set Copy as to PHP, Python or Node and you get the whole thing as runnable code, using PDO::prepare and execute for PHP, cursor.execute for Python, and connection.execute for Node. Keeping values out of the SQL string is what stops user input from turning into SQL injection.
What is the Reads as sentence for?
It describes your query in ordinary English, so you can check the intent without parsing the SQL. A join written the wrong way round, a filter on the wrong column, or a HAVING that should have been a WHERE all read as obviously wrong in a sentence long before they look wrong in code. It's also handy when you're sending a query to someone who doesn't read SQL.
Are the queries safe to run?
The output is valid SQL for the schema you describe, with identifiers quoted for your dialect and literal values escaped. Read it before you run it against real data, though. The tool only knows the table and column names you gave it, so it cannot know your actual types, indexes or row counts, and it will happily build a query that scans a very large table. If the query takes user input, use the placeholder mode rather than pasting values in.
What do the table aliases do?
An alias is a short name for a table inside one query. Set u for users and every reference becomes u.name instead of users.name, with FROM users AS u at the top. It's the convention in most hand-written SQL because it keeps long joins readable. The field is optional, so leave it empty to use the full table name.
Does my schema go anywhere?
No. Everything runs in your browser. The schema you paste and the queries you build are never sent to a server, nothing is logged, and the page keeps working offline once it has loaded.