Docs / Data extensions

LookupOrderedRows()

LookupOrderedRows is an AMPscript function in the data extensions category. count <= 0 returns all matches.

Syntax

LookupOrderedRows(de, count, "field asc|desc", col, value, ...)

Example

%%[ SET @top = LookupOrderedRows("Orders", 1, "Total desc", "Email", emailaddr) ]%%
Biggest order: %%=Field(Row(@top, 1), "OrderId")=%%
Rendered output
Biggest order: 1002

Output produced by AmpSend's AMPscript engine (validated against Salesforce's own test corpus) - not a hand-written result.

Try LookupOrderedRows in the editor - free, no signup

AmpSend runs AMPscript entirely in your browser: instant preview, named test scenarios, shared content blocks and data extensions, and an AI assistant that knows every supported function. Nothing leaves your machine.

Official Salesforce documentation

LookupOrderedRows in the official AMPscript reference - or browse the official index of AMPscript functions for platform behavior and edge cases.

Related data extensions functions