A.7 Sub-Query
SQL conditions allow a sub-query to be used in certain expressions. For example, a sub-query can be used in the 'in' expression to serve as the list value. This concept is supported in the Style Studio conditions.
The SQL sub-query is specified as a select statement inside a SQL condition. Using Style Studio, you can specify conditions on query variables such that they are dependent on the results from the sub-query. For example:
select * from orders where orders.state in (select customers.state from customers)
The result of the sub-query is interpreted according to the context.
If a scalar value is expected in the expression, the sub-query result (a sub-tree) is converted to a value using the following rules:
• If the root node is a sequence node, the value of the first child is returned.
• If the root node value is not null, the value is used as the scalar value.
• If the root node value is null and has child nodes, the value of its first child is returned.
• Otherwise, the value is null.
If a list is expected in the expression, the sub-query result is converted to a list using the following rules:
• If the root node is a table node, the first column of the table is converted to a list.
• If the root node is a sequence node, the sequence is converted to a list by converting each child of the root to its scalar value.
• Otherwise, a single value list is created using the scalar value of the root.
A sub-query call can be used in any place in a condition expression where a value is expected.
| << A.6 Aggregate Functions | © 1996-2013 InetSoft Technology Corporation (v11.4) | A.8 Sub-Selection >> |