LookupOrderedRows()
Retrieves a rowset from a data extension. You can specify the number of rows returned and the order that the results are returned in. If the order of results isn’t important, the LookupRows() function offers a simpler syntax.
This function returns a maximum of 2,000 rows.
LookupOrderedRows(1, 2, 3, 4, 5)
Ordinal | Type | Description |
---|---|---|
1 | string | Required. The name of the data extension. |
2 | number | Required. The number of rows to return. If you specify a value less than 1, the function returns 2,000 rows, which is the default value. |
3 | string | Required. The column and direction to sort by, using the syntax COLUMN_NAME SORT_ORDER , where SORT_ORDER is either ASC (ascending) or DESC (descending). |
4 | string or array | Required. The name of the column that contains the data to look up. To specify multiple column names, place the column names in an array. When you specify multiple column names, they’re connected using AND logic. |
5 | string or array | Required. The value to look up in the specified column. To specify multiple values, place the values in an array. If you specify an array for ordinal 4, you must specify an array of equal length for this ordinal. |
To use the function, specify the name of the data extension, the number of rows to return, and the column to sort by. Next, specify the column that contains the data that you want to retrieve and the value to search for in the specified column.
These examples reference a data extension that contains the customer data listed in this table.
ExternalId | FirstName | LastName | PreferredLanguage | RewardsTier |
---|---|---|---|---|
66057f8f-2003-4d08-8c87-b0a16a60d34e | Carolyn | Baumgartner | German | Silver |
be22021f-69ff-4b5c-99c3-bb42193343bc | Ernesto | Rondán | Spanish | Platinum |
e67e755d-d2b9-4a0e-8103-eee7958ef257 | Calvin | Green | English | Silver |
3b7e5138-75c6-4a2b-9155-598c6121d3ea | Tarō | Yamada | Japanese | Gold |
97b40dbb-2eaa-4880-9636-1639f92318a8 | Anna | Kowalski | Polish | Silver |
f86b8f65-6167-4faa-8b0c-8019e389982a | Mindy | Lee | English | Silver |
This example retrieves all rows in which the value of the RewardsTier
column is Silver. In the resulting rowset, the results are sorted by last name in ascending order. The function returns the default number of results (2,000).
The function outputs three results.
You can also specify multiple values for the column name or the value by placing the values in an array. Multiple values are connected using AND logic. This example retrieves the rows in which the value of PreferredLanguage
the value of RewardsTier
is Silver. The function sorts the results in ascending order by LastName
. The function returns the default number of results (2,000).
The function outputs the names of the customers whose preferred language is English and whose rewards tier is Silver.