Skip to content

Query Builder

The Query Builder in DBCode lets you construct SELECT queries visually. Add tables to a canvas, configure joins by dragging between columns, pick columns, set filters, and see the generated SQL update in real time. You can also use natural language to describe what you need and let AI build or modify the query for you.

Query Builder with two joined tables, selected columns, filters, and SQL preview

There are three ways to open the Query Builder:

  1. Tree icon — Click the Query Builder icon next to a database in the DB Explorer
  2. Right-click — Right-click a database and select Open Query Builder
  3. Command Palette — Run DBCode: Open Query Builder. If no connection is in context, you’ll be prompted to select one

The Query Builder opens as a full editor tab with the connection’s schema pre-loaded.

The Query Builder is divided into four areas:

  • Toolbar (top) — AI input bar, Run/Explain button, Save, and Open in Editor
  • Canvas (left) — Drag-and-drop area where tables appear as nodes and joins appear as edges
  • Config Panel (right) — Stacked sections for column selection, filters, GROUP BY, HAVING, ORDER BY, DISTINCT, and LIMIT
  • SQL Preview (bottom) — Read-only, syntax-highlighted SQL generated from the current model. Updates live as you make changes. Resizable by dragging the top border

Empty Query Builder interface showing toolbar, canvas, config panel, and SQL preview areas

  1. Click the Add Table button on the canvas
  2. Search for a table by name in the dropdown — it filters as you type
  3. Select a table to place it on the canvas as a node

Each table node shows the table name, its columns with data types, and primary/foreign key indicators. You can drag nodes to reposition them on the canvas.

To remove a table, select its node and press Delete or Backspace.

Tick a column’s checkbox on its table node to add it to the SELECT clause. The Columns section in the Config Panel then lists the selected columns in order:

  • Drag to reorder: grip handles on the left let you reorder selected columns, including across tables
  • Alias: click the alias field to give a column an output name
  • Aggregate: choose an aggregate function (COUNT, SUM, AVG, MIN, MAX) from the dropdown. When you apply an aggregate, GROUP BY is configured automatically for non-aggregated columns

Click + Add column for a searchable menu of every column. Each table has a select-all checkbox to add or remove all of its columns at once, handy for wide tables and available even when only one table is on the canvas.

When you add a second table that has a foreign key relationship with an existing table, DBCode automatically suggests a join.

Two tables on the canvas connected by an INNER JOIN with selected columns highlighted

To create a join manually:

  1. Drag from a column on one table node to a column on another
  2. The join appears as an edge connecting the two tables

Click a join edge to see the join type picker. Hover over a type to preview its Venn diagram and description, then click to select:

  • INNER JOIN — Only matching rows from both tables
  • LEFT JOIN — All rows from the left table, matching rows from the right
  • RIGHT JOIN — All rows from the right table, matching rows from the left
  • FULL JOIN — All rows from both tables
  • CROSS JOIN — Every combination of rows (Cartesian product)

To remove a join, select the edge and press Delete or Backspace.

The Where section lets you build WHERE clause conditions without writing SQL:

  1. Click + condition
  2. Select a column from the dropdown
  3. Choose an operator: =, !=, >, <, >=, <=, LIKE, NOT LIKE, CONTAINS, NOT CONTAINS, IN, NOT IN, IS NULL, IS NOT NULL, BETWEEN, or NOT BETWEEN
  4. Enter a value

DBCode quotes each value based on the column’s type: text is quoted ('GER'), numbers stay bare (18), and IN lists are split on commas and quoted element by element ('EU', 'US'). To pass a value through verbatim, such as a column reference or a function call like NOW(), toggle the fx button on that condition. For text comparisons, the Aa button makes the match case-insensitive by wrapping both sides in UPPER().

The conditions in a group are joined by a single Match operator, AND or OR, selected at the top of the group. To mix AND and OR, nest a group: click + group to add a sub-group with its own Match operator. This produces parenthesised SQL, for example language = 'GER' AND (region = 'EU' OR region = 'US').

Drag the grip handle on any condition or group to reorder it, or to move it into or out of a group. Removing the last condition from a group removes the empty group automatically.

The Group By section lets you group results by one or more columns. Select columns from the dropdown to add them. When you apply aggregate functions to columns in the Columns section, non-aggregated selected columns are automatically added to GROUP BY.

The Having section adds conditions that filter grouped results (like WHERE, but applied after aggregation). Add conditions with a column, operator, and value, just like the Where section.

The Order By section controls result sorting:

  1. Click Add to add a sort column
  2. Select the column from the dropdown
  3. Toggle between ASC (ascending) and DESC (descending)
  4. Drag to reorder when multiple sort columns are defined
  • DISTINCT — Toggle the checkbox to eliminate duplicate rows
  • LIMIT — Enter a number to cap the result set size

The text input at the top of the toolbar accepts natural language descriptions. Type what you need and press Enter:

  • Build from scratch — “Show me all customers with orders over $100 in the last 30 days”
  • Modify existing — “Add a date filter for last month” or “Change to LEFT JOIN”
  • Aggregate — “Show total sales by category”

The AI reads your current query model and schema, then returns an updated model. The canvas, config panel, and SQL preview all update to reflect the changes. You can undo AI changes with Ctrl+Z / Cmd+Z.

Click the Run button (or use the dropdown for Explain / Analyze where supported by your database) to execute the generated SQL. Results appear in the standard Results Pane, just like running a query from the SQL Editor.

The Query Builder tab stays open so you can refine and re-run.

Click Save to Library to save the query builder state to your Library panel:

  • First save — Prompts for a name and scope (Project or Personal), then stores the full visual state (tables, joins, filters, columns, positions) along with the generated SQL
  • Subsequent saves — Updates the saved item silently (no prompt)
  • Save As New — Creates a copy with a new name

Opening a saved query builder from the Library restores the full visual state — table positions, joins, column selections, filters, and all configuration. If the query builder is already open, clicking the saved item reveals the existing tab instead of opening a duplicate.

Click Open in Editor to copy the generated SQL into a new SQL Editor tab bound to the same connection. This is useful when you want to hand-edit the query or save it as a .sql file.

The Query Builder works with all databases supported by DBCode. SQL generation adapts to each dialect automatically:

  • Identifier quoting (double quotes, backticks, or square brackets)
  • LIMIT vs TOP vs FETCH FIRST for row limiting
  • Schema qualification where applicable

All changes to the query model support undo and redo:

  • Ctrl+Z / Cmd+Z — Undo
  • Ctrl+Shift+Z / Cmd+Shift+Z — Redo

This includes AI-generated changes, so you can safely experiment and revert.