Introduction
Sometimes, the result of one query may be used as an input parameter for another query. In such situations, we use the nested query feature available in the WSO2 Data Services Server.
Building the sample
The sample data service NestedQuerySample should be deployed using the instructions in Samples Setup section.
Running the sample
The sample service can be run using the TryIt tool, which is bundled with the WSO2 Data Services Server, or a code-generated java client sample as discussed in the Data Services Clients section.
Service description
The service contains the following queries.
- employeesInOfficeSQL - Takes in an office code and prints the details of all the employess in that office.
- listOfficesSQL - Lists all the offices in the database. When office information is printed, all the employees that belong to an office are also printed using a nested query, which refers to the employeesInOfficeSQL query.
- customerNameSQL - Takes in the customer number as a parameter and returns the customer name. In the result section of this query, there is no "rowName" defined; only an element wrapper. With this option, a separate element will not be created for every record in the result. But the record content will be directly added to the outer element. This is best used in a query where, there is only one record to be returned.
- customerOrdersSQL - Prints the details of all the orders that are in the database. In the result elements, a nested query which references the customerNameSQL query is used. In this way, the name of the customer who placed the order can also be returned with the order details.
Sample run
Sample run of the service using the TryIt tool is shown below.
Nested query based operation invocation using the "listOfficesSQL" query:
Nested query based operation invocation using the "customerOrdersSQL" query:
Nested query based operation invocation using the "customerNameSQL" query: