ORDER BY, LIMIT and OFFSET
Sorting on one or more features, ascending and descending, the original file order, spatial sequencing with GEOMETRY, and paging with LIMIT and OFFSET.
ORDER BY sorts the records; LIMIT and OFFSET page through them. Both come after GROUP BY and before USING.
Syntax#
ORDER BY <feature> [ASC|DESC] [, <feature> [ASC|DESC] ...]
ORDER BY ORIGINAL
ORDER BY GEOMETRY(<condition>)
LIMIT <n>
OFFSET <n>ORDER BY features#
Each sort key is a plain feature (a path, or BIN(...)); aggregates, aliases and arithmetic are not sort keys. ASC is the default. Several keys sort by the first, then the second.
GET qid, attribute.Name, aabb.height WHERE type = IFCDOOR ORDER BY aabb.height DESC, attribute.NameGET attribute.Name, attribute.Elevation WHERE type = IFCBUILDINGSTOREY ORDER BY attribute.ElevationA grouped query cannot be ordered by its aggregates (ORDER BY COUNT(qid) is a syntax error); order the groups by their key or sort the records in the client.
ORDER BY ORIGINAL#
ORDER BY ORIGINAL returns the objects in the order they have in the model file. It is not available inside a nested relation query, where it raises BimWorksQueryError.ORDER_BY_ORIGINAL_ORDER_NOT_SUPPORTED.
GET qid, attribute.Name WHERE type = IFCWALL ORDER BY ORIGINALORDER BY GEOMETRY#
ORDER BY GEOMETRY(<condition>) sequences the result spatially: starting from the first object that matches the condition, each next record is the nearest remaining object by bounding-box centre. It exists for walk-throughs and sequences (BSL frames, animations) rather than for reports.
GET qid, attribute.Name WHERE type = IFCDOOR ORDER BY GEOMETRY(attribute.Name = "Main entrance")LIMIT#
LIMIT n keeps the first n records after sorting. LIMIT 0 and LIMIT -1 mean no limit (the validator suggests dropping the clause). A limit below -1 returns nothing, and the validator warns. Inside a nested relation query, LIMIT applies per parent object (get#nested).
GET qid, attribute.Name, aabb.height WHERE type = IFCWALL ORDER BY aabb.height DESC LIMIT 10OFFSET#
OFFSET n skips the first n records; with LIMIT it pages. A negative offset has no effect.
GET qid, attribute.Name WHERE type = IFCWALL ORDER BY attribute.Name LIMIT 50 OFFSET 100Used in#
- Grouping and aggregates — sorted groups and the top-n idiom.
- Run a BQL query — paging a large result.