Select



SELECT reads documents from one or more schemas.
SELECT [DISTINCT] [TOP n] { * | alias.* | expression [as Name], ... }
[INTO TargetSchema]
FROM Schema [as alias]
[INNER JOIN | OUTER JOIN Schema as alias ON conditions] ...
[WHERE conditions]
[GROUP BY expression, ...]
[ORDER BY expression [ASC | DESC], ...]
[OFFSET n]

Notes on SELECT *

SELECT * returns every field found in the selected documents. Since documents in a schema don't need to have the same fields, SELECT * must examine every selected document to build the list of fields.

Inconsistent schema fields

Fields are not guaranteed to exist in every document. Fields that are selected but missing from a document are returned as NULL. Set WarnMissingFields to be warned about them.


Fields and expressions can be given a name with as. The as keyword is required. Names that contain spaces must be quoted. Expressions without a name are returned as Expression0, Expression1 and so on.

round-pushpin Selects all fields from the Word schema.
SELECT * FROM WordList:Word

round-pushpin Selects specific fields, an expression and a function from the Word schema.
SELECT
    Id,
    Text,
    Id * 10 as Score,
    ToUpper(Text) as 'Upper Case'
FROM
    WordList:Word
WHERE
    LanguageId = 1

round-pushpin Selects all of the fields of one of the joined schemas.
SELECT
    w.*
FROM
    WordList:Word as w
INNER JOIN WordList:Language as l
    ON l.Id = w.LanguageId
WHERE
    l.Name = 'German'




SQL :: Aggregate Functions
Aggregate functions compute one value from a group of rows.
SQL :: Avg
Returns the average (arithmetic mean) of the values in each group.
SQL :: Between
Matches values that fall within a given range.
SQL :: Count
Returns the number of values in each group. Count(0) and Count(*) count the documents in each group.
SQL :: CountDistinct
Returns the number of distinct values in each group. Values are compared without regard to case unless caseSensitive is true.
SQL :: Delete
Delete removes the documents that match the given criteria.
SQL :: Distinct
Removes duplicate rows from the results of a SELECT.
SQL :: Expressions
Literals, operators, comments and variables in KBSQL.
SQL :: GeometricMean
Returns the geometric mean of the values in each group: the nth root of their product. Useful for growth rates and ratios.
SQL :: Group By
Group by collapses a result set into one row per distinct set of values.