Sub-queries are queries used inside a query condition expression. The result of the sub-query is used when evaluating the expression. This functionality is only supported for hierarchical data sources like XML, SOAP, etc. You cannot use this feature with a non-hierarchical data source like JDBC. This concept also exists in SQL, but there are a few important differences:
A sub-query can be invoked from an expression using the ‘query()’ function. name in (query('all names')) In this example, the results returned by the query, ‘all names’, are used as the list value. The query must be defined in the query registry. If the sub-query expects parameters (user variables), the variable values can be passed to the sub-query in the function call. name in (query('all names', state = state) One or more parameters can be added to the call as needed. Each variable is passed in as a name-value pair.
In this example, the name of the variable is ‘state’, and the value of the variable is the ‘state’ node value in the current record. Any name values can be used as the variable value, including variables, sub-queries, nodes or attributes, and constant values.
Next we provide an example of using a sub-query to get a list of values from an XML data stream and then using the query result in the condition of another query to retrieve a list of employees. The query retrieves a list of all employees with evaluation scores above a score of 3.
First, create a query to retrieve the employee ID’s of employees with scores above a certain value.
Copyright © 2024, InetSoft Technology Corp.