Reference
DQL reference
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 aggregatesCOUNT(*),COUNT(c_x),SUM,AVG,MINandMAX, each optionally withAS alias. - JOIN: one further table, joined where a column of each is equal.
- WHERE: comparisons with
=,!=,<>,<,>,<=,>=,LIKE(with%wildcards),IN (...),BETWEEN ... AND ...andIS [NOT] NULL, combined withAND,OR,NOTand 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
LIMITandORDER BYwhen 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 DESCSELECT 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 >= 40UNION, 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 = falseEach 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.