---
schema_version: "1"
id: bf5b7bbb6c62501121af4e3e0dfc0c6cda10361d0aa4360494186702b9430826
title: LookupOrderedRows()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/guides/mc-programmatic-content/ssjs_platformDataExtensionLookupOrderedRows.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformDataExtensionLookupOrderedRows.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 42c131edbd45374102cb1b80bbe774bc08566f79793664d6d4a3bbac8a3985a0
products:
  - Marketing Cloud Engagement APIs and Programmatic Languages
  - Marketing Cloud
---
# 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()](https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformDataExtensionLookupRows.md) function offers a simpler syntax.

This function returns a maximum of 2,000 rows.

## Syntax

`Platform.Function.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). Specify multiple columns by separating them with a comma. For example, `"LastName ASC, FirstName ASC"`. |
| 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.                                                     |

## Usage

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.

<!-- Names are drawn from the list of Salesforcelandian characters (https://confluence.internal.salesforce.com/pages/viewpage.action?pageId=668086572), with the exceptions of Taro Yamada and Anna Kowalski. These names are the equivalents of John/Jane Doe in Japanese and Polish, respectively. -->

| 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      |

### Query with a Single Column Name and Value

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).

```js
<script runat="server">
     var dataRows = Platform.Function.LookupOrderedRows('CustomerData', 0, 'LastName ASC', 'RewardsTier', 'Silver');
     if(dataRows && dataRows.length > 0) {
          for(var i=0; i<dataRows.length; i++) {
               Platform.Response.Write(dataRows[i]["FirstName"] + " " + dataRows[i]["LastName"] + "<br/>");
          }
     }
</script>
```

The function outputs three results.

```
Carolyn Baumgartner
Calvin Green
Anna Kowalski
```

### Query with Multiple Column Names and Values

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).

```js
<script runat="server">
     var dataRows = Platform.Function.LookupOrderedRows('CustomerData', 0, 'LastName ASC', ['PreferredLanguage', 'RewardsTier'], ['English', 'Silver']);
     if(dataRows && dataRows.length > 0) {
          for(var i=0; i<dataRows.length; i++) {
               Platform.Response.Write(dataRows[i]["FirstName"] + " " + dataRows[i]["LastName"] + "<br/>");
          }
     }
</script>
```

The function outputs the names of the customers whose preferred language is English and whose rewards tier is Silver.

```
Calvin Green
Mindy Lee
```
