Functions that join records from subqueries.
Returns a record from a subquery (the lookup table) producing a match between a field in the source table (sourceField
) and a field in the lookup table (lookupField
).
In contrast to the lookup
command, the lookup
function nests all included fields in the form of a DQL record.
In a case, where more than one match is produced in the lookup table, only the first matching record of the lookup table is returned.
lookup(lookupTable, lookupField [, sourceField] [, executionOrder])
Parameter
Type
Description
Required
lookupTable
execution block
Subquery producing the lookup table.
required
sourceField
expression
The matching field in the source table (left side).
optional
lookupField
expression
The matching field in the lookup table (right side).
required
executionOrder
Defines which side of the join will be executed first. The allowed values are auto
, leftFirst
, rightFirst
. The default value is auto
.
optional
The data type of the returned value is record
.
data record(location = "Vienna", bookings = 1337),record(location = "London", bookings = 2431)| fieldsAdd result = lookup([data record(city = "Vienna", country = "Austria"),record(city = "Barcelona", country = "Spain")],sourceField:location,lookupField:city)
Query result:
location
bookings
result
Vienna
1,337
city: Vienna
country: Austria
London
2,431
null
In a case, where more than one match is produced in the lookup table, only the first matching record of the lookup table is returned.
data record(location = "Barcelona"),record(location = "London")| fieldsAdd result = lookup([data record(team = "FC Barcelona", city = "Barcelona"),record(team = "Chelsea", city = "London"),record(team = "FC Arsenal", city = "London"),record(team = "Tottenham Hotspur", city = "London")],sourceField:location,lookupField:city)
Query result:
location
result
Barcelona
team: FC Barcelona
city: Barcelona
London
team: Chelsea
city: London
The same limits as described for the join
command apply.