Help home > SQL Builder

SQL Builder

Build SQL by placing tables, checking columns and connecting columns to join them. Besides SELECT, you can build INSERT, UPDATE, DELETE and CREATE VIEW statements.

What you can do

TaskHow to open
Open an empty SQL Builder🧩 SQL Builder in the top bar, "Tools" → "SQL Builder" in the menu, or right-click a connection name in the tree and choose "SQL Builder"
Open with a table already addedRight-click a table or view in the tree and choose "Open in SQL Builder"

Getting started: building a SELECT (4 steps)

  1. Place tables

    Drag and drop tables from the tree, or pick them with + Add Table. Tables linked by foreign keys are joined automatically (see Tables and joins).
  2. Choose columns

    Check columns in a table to list them in the grid below and include them in the SELECT.
  3. Add conditions and sorting

    Type something like = 1 in the "Condition" column of the grid to add a WHERE clause (see Column grid).
  4. Run

    The finished SQL appears at the bottom right. ā–¶ Run runs it in a SQL tab.

Tables and joins

TaskHow
Move a tableDrag its header
JoinDrag a column and drop it on a column of another table (a line connects them). Tables with foreign keys between them are joined automatically when added
Change or remove a joinClick the line and choose "Inner Join", "Left Outer Join", "Right Outer Join", "Full Outer Join" or "Delete Join". Joins other than inner joins are drawn as dashed lines
Change the aliasDouble-click the header, or right-click it and choose "Change Alias...". Aliases are assigned A, B, C… in the order tables are added
Select or clear all columnsRight-click the header and choose "Select All Columns" or "Clear Selection"
Make a table firstRight-click the header and choose "Move to First (First in FROM / Update Target)". The first table's header has a different color
RemoveƗ in the header
Tables without a joinTables not connected by a line become a CROSS JOIN (every combination). That can produce a huge number of rows, so check that you haven't forgotten a join.

Column grid (show, alias, aggregate, sort, condition)

ColumnContents
↑ ↓Changes the order of columns in the SELECT
ShowWhether the column appears in the SELECT. Uncheck it to use the column only for conditions or sorting
AliasThe AS name. When empty, the column name is used
AggregateCOUNT, SUM, AVG, MIN, MAX, COUNT DISTINCT. When any column is aggregated, the other shown columns go into GROUP BY
Sort, OrderAscending or descending. With several sort columns, they are applied in ascending "Order" (grid order when empty)
ConditionStart with an operator (=, <>, >=, LIKE, IN, IS, BETWEEN and so on) to make it a condition on that column. Anything else goes into the WHERE clause as is. Multiple conditions are combined with AND. Conditions on aggregated columns go into HAVING

Condition examples: = 1, LIKE 'Sm%', IN (1, 2, 3), IS NULL, BETWEEN '2024-01-01' AND '2024-12-31'

DISTINCT in the toolbar removes duplicates, and Max limits the number of rows (TOP in SQL Server, FETCH FIRST in Oracle, LIMIT elsewhere).

SQL types

TypeSQL built
SELECTA SELECT with the chosen columns, joins, conditions, aggregates and sorting
CREATE VIEWA statement that turns the SELECT into a view named "View name"
INSERTInserts one row into the first table, using the "Target" columns and their "Value"
UPDATESets the "Target" columns of the first table to "Value". "Condition" becomes the WHERE clause
DELETEDeletes the rows of the first table that match "Condition"
UPDATE and DELETE without conditionsEvery row is affected. You are asked to confirm when you run it in the SQL tab (this can be changed in the settings).

Write each "Value" as an SQL expression. Quote text with ', as in 'Smith'. An empty value means NULL.

Opening in a SQL tab and running

The finished SQL appears at the bottom right. Open in SQL Tab puts it in a new SQL tab, and ā–¶ Run (SELECT only) opens it and runs it right away. From the second time on, ā–¶ Run replaces the SQL in the previous result tab and runs it (if you closed that tab or edited its SQL by hand, it runs in a new tab). For INSERT, UPDATE and DELETE, review the statement in the SQL tab before running it.

The SQL Builder's contents are not saved to a file. To keep the SQL, save it from the SQL tab.

FAQ

"+ Add Table" is disabled

No connection is selected, or it isn't connected. Select a connection in the list at the top left and connect to it in the tree.

The "+ Add Table" list is empty

In SQL Server and similar databases, if the connection settings don't specify a database, you are connected to the login's default database (such as master), which has no user tables. Choose the database in the database list to the right of the connection (choosing "connection name / database name" does the same).

I can't draw a join line

Grab a column row and release it over a column row in another table. You can't join columns within the same table (add the same table twice for a self-join).

Tables disappeared when I changed the connection

The other connection may not have those tables, so changing the connection removes the tables you placed.

ā–² Back to top

← Musubi SQL website (download)