[Download] | [Documentation Home] | [Release Note]
When using a data service query, we may need to use the result of one query to be used as an input parameter of another query. This can be achieved using WSO2 Data Services Server which is explained here.
First add the query with an input parameter which is evaluated as the result of another query. So here the 'customerNumber' input maping will be result of another query.
Figure 1: Define Query 1
Now add the query which will result 'customerNumber'. Below shows the query page with the query 'customerOrderSQL'.
Figure 2: Define Query 2
Then go to Add New Output Mapping option of the above query page and define the values as below. Here 'query' should be selected as the mapping type which will allow to select the query name and define query parameter mapping. Now as shown in below the query 'customerNameSQL' will be invoked with 'customerNumber' parameter which is a result of 'customerOrderSQL'.
Figure 3: Define Nested Query Mapping
Add an operation with customerOrderSQL as follows.
Figure 4: Define Nested Query Operation
So when we invoke the operation result will contain the nested result element 'Customer' which is returned from 'customerNameSQL' query.
Figure 5: Nested Query Result
As described above, nested queries can be configured and invoked in data services. In the configuration syntax this is achieved by defining call-query element as a result element of a query.
Figure 6: Call-query syntax for nested queries
Here is the description of the child elements and attributes of the call-query.
From call-query/with-param/@query-param and call-query/with-param/@column attributes only one is used in a single call-query/with-param element.