DEFINE and RETURN clauses

All EQL statements begin with either DEFINE or RETURN. DEFINE is used to generate an intermediate result that will not be included in the query result. RETURN indicates that the statement result should be included in the query result.

DEFINE

You can use multiple DEFINE clauses to make results available to other statements. Typically, DEFINE clauses are used to look up values, compare attribute values to each other, and normalize data.

Its syntax is as follows:

DEFINE <recordSetName> AS ...

In the following example, the RegionTotals record set is used in a subsequent calculation:

DEFINE RegionTotals AS
SELECT SUM(Amount) AS Total
GROUP BY Region;

RETURN ProductPct AS
SELECT 100*SUM(Amount) / RegionTotals[Region].Total AS PctTotal
GROUP BY Region, Product Type

RETURN

RETURN provides the key for accessing EQL results from the Endeca Server query result. This is important when more than one statement is submitted with the query.

Its syntax is as follows:

RETURN <recordSetName> AS ...

The following statement returns for each size the number of different values for the Color attribute:

RETURN result AS 
SELECT COUNTDISTINCT(Color) AS Total
GROUP BY Size