Subquery – is an EQL-query, nested in another EQL-query (is a component of another EQL-query). The nesting depth cannot be more than 16 subqueries or 1000 operators. It is recommended to parenthesize subqueries, to avoid calculation errors.
Subqueries allow filtering root objects by properties of related objects.
Subqueries can be created according to one of the two rules:
-
FROM entity SELECT property WHERE expression
-
SELECT property FROM entity WHERE expression
where: entity – is an object with which the subquery works;
property – a field in the current object;
expression – expression for filtering object instances. Can also be a subquery.
Example 1. Search tasks with deal name matching the task name.
The query will look like this: Contractor in (FROM Contact SELECT Contractor WHERE Name = PARENT.Subject AND Contractor in (FROM Sale SELECT Contractor WHERE Name = ROOT.Subject))
Note, that if a property name matches a reserved word (not case-sensitive), then this property must be in brackets: [Parent] = 1.
Example 2. Search contractors, whose contacts have high and low priority.
In this case, Contractor is the root object. A Contact is an object, related to the root object, Contractor. Priority is a field of the related object, Contact. In such a query, you can use a subquery to specify, that the Priority field of the Contact object is to be compared.
The query will look like this: Contacts IN (Priority IN (Enum('High'), Enum('Low')))
In this case, first the IN operator is executed in the subquery (selects contacts with high and low priority), next, the IN operator in the query is executed (selects contractors with contacts, selected by the subquery).
Copyright © 2006–2019 ELMA