Queries: SELECT and clauses
40 reference entries
- $IDENTITY
pseudo-column reference $IDENTITY resolves to the identity column
- $ROWGUID
pseudo-column reference $ROWGUID resolves to the ROWGUIDCOL column
- FOR BROWSE
browse mode: adds hidden key columns for DB-Library updates
- FOR JSON
serializes the rowset to JSON text
- FOR JSON AUTO
nests JSON by table alias order
- FOR JSON PATH
dot-separated aliases build nested JSON objects
- FOR XML
serializes the rowset to XML
- FOR XML AUTO
nests elements by table alias order in the select list
- FOR XML EXPLICIT
universal-table shape (Tag, Parent columns) drives the XML tree
- FOR XML PATH
column aliases are XPath-like paths; PATH('') with no column name concatenates values
- FOR XML RAW
one <row> element per row; columns become attributes (or elements with ELEMENTS)
- GROUP BY ... WITH CUBE / WITH ROLLUP
non-ISO WITH CUBE / WITH ROLLUP suffix
- GROUP BY () (grand total)
empty grouping set: aggregates over all rows
- GROUP BY ALL (deprecated)
non-ISO GROUP BY ALL (deprecated)
- GROUP BY CUBE
cross-tab super-aggregates (2^n grouping sets)
- GROUP BY GROUPING SETS
computes several GROUP BY results in one pass and unions them
- GROUP BY ROLLUP
hierarchical super-aggregates from right to left of the key list; rolled-up keys are NULL
- OPTION clause
container for query hints on a statement
- ORDER BY ... OFFSET
skips the first N ordered rows
- ORDER BY ... OFFSET ... FETCH
page limit after OFFSET
- OVER ... ROWS / RANGE frame
ROWS (physical offsets) or RANGE (logical peers) frame bounds
- Queries (overview)
none (documentation, rules or examples)
- Recursive queries using common table expressions
iterative fixpoint: anchor rows, then recursive member joined to the prior level until no rows (MAXRECURSION default 100, 0 = unlimited)
- SELECT - FOR clause
serializes the rowset into XML or JSON text/xml
- SELECT - GROUP BY
groups rows by key columns and computes aggregates
- SELECT - HAVING
post-aggregation filter
- SELECT - INTO clause
creates the table and inserts all rows in one statement
- SELECT - ORDER BY clause
sorts the result; ORDER BY is the only guarantee of output order
- SELECT - OVER clause
window computation: partition, order, frame; rows are not collapsed
- SELECT - WINDOW clause
declares reusable named window specifications (PARTITION BY, ORDER BY, frame)
- SELECT (overview)
full query pipeline: bind sources, join, filter, group, aggregate, project, distinct, sort, limit
- SELECT ALL
no-op marker (default)
- SELECT clause
projection: computes expressions, assigns aliases, expands *
- SELECT DISTINCT
removes duplicate rows across all projected columns
- SELECT examples
none (documentation, rules or examples)
- TOP
row limiter; without ORDER BY the chosen rows are not deterministic
- TOP ... PERCENT
percentage limiter
- TOP ... WITH TIES
TOP WITH TIES
- WHERE
row filter
- WITH common_table_expression
defines named subqueries usable in the next statement (SELECT, INSERT, UPDATE, DELETE, MERGE)