SELECT
FROM type_list
SELECT * | selection_list
[WHERE where_condition]
[GROUP BY group_expr]
[ORDER BY order_expr]
[LIMIT limit_expr]
[OFFSET offset_expr]
[DEPTH depth_expr]
type_list
type reference
- Specify the type object to be selected
- For example a type list could be ‘User U’, ‘Car C’, …
type
name
- A valid type in the database
reference
name
selection_list
selection_list_element [, selection_list_element]
- Contains the attributes that need to be selected from the type
- All attributes can be selected by using the symbol ‘*’
- Specific attributes can be given by using a comma seperated list
- “FROM Object o SELECT o.Name, o.Age” → will return only the attributes “Name” and “Age”
- “FROM Object o SELECT *” → will return everything
selection_list_element
selection_source aliasopt
- A selection list element is one part of the selection list
- It can be aggregated using an aggregate function and
- It can be followed by an optional alias
selection_source
aggregate | func_call | reference.id
- An selection_source could be an aggregate, a function call or a simple an id.
id
identifier.identifier [, identifier.identifier]
- An id is composed by an identifier a dot and a second identifier – or a list of them.
- An id could be ‘U.Name’ or ‘U.Friends.Age’.
identifier
name
- An identification name, for example the name of an type and an object attribute
- User.Name is an id of two identifiers for an attributename ‘Name’ of a type ‘User’,
aggregate
aggregate_name ( aggregate_argument )
- An aggregate countains an aggregate name and an argument.
aggregate_name
COUNT | AVG | MIN | MAX | SUM
- An aggregate can be a COUNT an AVG an MIN an MAX or a SUM.
- “COUNT” will return the number of elements, e.g. a user has 3 friends then is the result of the query ‘COUNT(U.Friends)’ will be equals ‘3’.
- “AVG” calculates the average of the given numeric elements.
- “SUM” will return the sum of the given numeric elements.
- “MIN”/”MAX” will return the minimal or maximal value of a list of values, e.g. ‘MAX(U.Friends.Age)’.
- It is possible to extent the list of aggregate function by implementing a database plug-in.
aggregate_argument
expression
expression
term | unary_expression | binary_expression
term
id | string_literal | number | func_call | aggregate | tuple | tuple_set | partial_select_statement
tuple
( expression_list )
expression_list
expression [, expression]
tuple_set
[ expression_list ]
- IMPORTANT: the square brackets are not optional
partial_select_statement
( select_statement )
unary_expression
unary_operator term
unary_operator
NOT | ++ | -- | ~
binary_expression
expression binary_operator expression
- A binary expression is an expression which takes two arguments and combines them with a binary operator.
binary_operator
+ | - | * | / | % | & | | | ^ | = | > | < | >= | <= | <> | != | !< | !> | AND | OR | LIKE | NOT LIKE | IN | NOTIN
func_call
function_name ( function_arguments )
- A function call contains a function name followed by the function arguments in brackets.
function_name
CONCAT | TOUPPER | MAXWEIGHT | SUBSTRING | TOP | CURRENTDATE
- “CONCAT(STRING, STRING)” returns the concatenation of two arguments of type string.
- “TOUPPER(STRING)” returns the given string converted to all uppercase characters
- “CURRENTDATE()” returns the current time stamp.
- “SUBSTRING(STRING, START, END) return an subtring of an given string value
- “TOP(LIST)” returns the first value of a list of values.
- “MAXWEIGHT(WEIGHTETLIST)” returns the highest weight of an weightet list.
function_arguments
expression_list
aliasopt
EMPTY | AS aliasopt_name
- An aliasopt can be empty or an expression which starts with the keyword AS followed by an name.
- For example ‘U.Name AS Name’ → ‘Name’ is the alias for ‘U.Name’.
aliasopt_name
name| string_literal
where_condition
EMPTY | WHERE expression
- The ‘WHERE’ condition, if given, includes the conditions that an attribute must satisfy to be selected
- For example the existing users are Burns, Crowley, Simpson and the query ‘FROM User U SELECT U.Name WHERE U.Name = ‘Simpson’ ‘ will return all users with the attribute ‘name’ set to ‘Simpson’
group_expression
EMPTY | GROUP BY id_list having_condition
- The group by expression groups the result of the query by the given attribute
- For example the following query groups the result by the attribute ‘name’, e.g. ‘FROM User U SELECT U.Name, COUNT(U.Age) GROUP BY U.Name’
having_condition
EMPTY | HAVING expression
- The having condition references the attributes which are selected in the group expression
- The result contains the attributes which satisfy the given condition / expression, e.g. ‘FROM User U SELECT U.Name, COUNT(U.Age) GROUP BY U.Name HAVING COUNT(U.Age) > 3’
id_list
reference.id [, reference.id]
- Is a simple id or a list of id’s
order_expression
EMPTY | ORDER BY order_attribute_list order_attribute_direction
- The order expression returns the result in an sorted order
- For example the result of the query ‘FROM User U SELECT U.Name, U.Age AS ‘The Age’ ORDER BY U.Name, ‘The Age’’ is sorted by the attribute ‘name’
order_attribute_list
reference.id | string_literal
order_attribute_direction
EMPTY | ASC | DESC
- If the query has an given order_expression you can give a sorting direction
- the results either sorted ascend with the keyword ASC or descend with the keyword DESC
limit_expression
EMPTY | LIMIT number
- The limit expression returns only the given number of objects
- For example ‘FROM User U SELECT U.Name LIMIT 10’ returns only 10 name attributes
offset_ expression
EMPTY | OFFSET number
- If an offset is set then the result contains the objects starting with the given number
- For example ‘FROM User U SELECT U.Name OFFSET 2’ return all results starting with the third result
depth_expr
EMPTY | DEPTH number
- Set the ressolution depth for an result
- For example if the depth is set to 2 and the attribute ‘friends’ is selected of an user object, then you get the friends of the friends → ‘FROM User U SELECT * DEPTH 2’
- Default-Depth is set to 0