[Download]
| [Documentation Home] | [Release Note]
Nested Query Sample
Introduction
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, in that situation we use the nested query
feature which is available inWSO2 Data Services
Server.
Prerequisites
The sample data service "NestedQuerySample" should be deployed as per the instructions
mentioned in
Deploying Samples
section.
Running the Sample
The sample service can be run using the "tryit" tool, which is bundled withWSO2 Data Services
Server.
Service Definition
The service contains the following queries.
- employeesInOfficeSQL - This query takes in an office code, and prints the
details of all the employess in that office.
- listOfficesSQL - This query lists all the offices that is in the database. When
office information is printed, all the employees that belongs to an office is
also printed using a nested query, which refers to the "employeesInOfficeSQL"
query.
- customerNameSQL - This query takes in the customer number as a parameter and
return the customer name. In this query, in the result section, 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 - This query prints the details of all the orders that are in
the database, in the result elements, a nested query which references
"customerNameSQL" query is used. In this way, the name of the customer who
placed the order can be also returned with the order details, by using the
nested query.
Sample Run
A sample run of the service using the "tryit" tool is shown below.
Figure 1: Nested query based operation invocation using the "listOfficesSQL" query.
Figure 2: Nested query based operation invocation using the "customerOrdersSQL"
query.