Guide

Reference

DQL reference

2 min readOpen in Neblex

DQL reads and maintains your data tables with familiar SQL-like statements. Tables are referred to by their name and columns by their c_ names; system columns cannot be used. For the runner and the builder, see Query tables (DQL).

SELECT

SELECT [DISTINCT] columns
FROM table [alias]
[JOIN other [alias] ON alias.c_column = other.c_column]
[WHERE conditions]
[GROUP BY columns]
[ORDER BY column [ASC|DESC], ...]
[LIMIT n]
  • Columns: column names, *, or aggregates COUNT(*), COUNT(c_x), SUM, AVG, MIN and MAX, each optionally with AS alias.
  • JOIN: one further table, joined where a column of each is equal.
  • WHERE: comparisons with =, !=, <>, <, >, <=, >=, LIKE (with % wildcards), IN (...), BETWEEN ... AND ... and IS [NOT] NULL, combined with AND, OR, NOT and parentheses. Text values go in single quotes.
  • GROUP BY: when you select aggregates together with plain columns, every plain column must be in GROUP BY.
  • LIMIT: how many rows to return. Results are capped even without it, so add LIMIT and ORDER BY when you need a specific slice.
SELECT c_region, COUNT(*) AS kits, AVG(c_peak_sun) AS sun
FROM solar_regions
WHERE c_peak_sun >= 3.5
GROUP BY c_region
ORDER BY sun DESC
SELECT f.c_frame, i.c_diameter
FROM pump_frames f
JOIN pump_impellers i ON f.c_frame = i.c_frame
WHERE f.c_max_flow >= 40

UNION, INTERSECT, EXCEPT, WITH and sub-queries are not supported; use a join or two queries.

Placeholders in models

Inside rules, functions and attribute option queries, ${attributes.Name} stands for the current value of an attribute. Text is quoted for you, numbers and true/false are inserted as they are, and an empty value becomes NULL, so WHERE c_size = ${attributes.Size} works for every type. In attribute option queries the name must be one word; in function scripts, ${attributes['Name with spaces']} also works.

INSERT, UPDATE and DELETE

INSERT INTO table (c_a, c_b) VALUES ('x', 1), ('y', 2)
UPDATE table SET c_price = 120 WHERE c_sku = 'A-100'
DELETE FROM table WHERE c_active = false

Each needs the matching permission on data tables: create, update or delete. UPDATE and DELETE always need a WHERE clause that picks out specific rows; to empty a table, use Truncate on its rows page.