Ordering and Limiting Results

Ordering results

You can specify the order of rows in your response using the ORDER BY clause, which consists of one or more comma-separated sequences of:

FieldName ('ASC' | 'DESC')?

If you do not specify ASC or DESC after a field name, the Google Ads API will default to ASC.

The following ORDER BY clause sorts a campaign-level report by descending impressions and ascending campaign name:

ORDER BY metrics.impressions DESC, campaign.name ASC

Ordering is not allowed:

  • By attributes of non-selected resources
  • By non-selected metrics
  • By non-selected segments
  • For fields of the following types:
    • MESSAGE
    • Repeated fields
    • Attributes of repeated fields

Limiting the number of results

You can limit the total number of results returned using the LIMIT clause. Combining this with results ordering, you can produce "top N" reports, such as a report containing the five campaigns with the highest impressions over the last 30 days:

SELECT
  campaign.id,
  campaign.name,
  metrics.impressions
FROM campaign
WHERE segments.date DURING LAST_30_DAYS
ORDER BY metrics.impressions DESC
LIMIT 5

Filtering is not allowed:

  • On segments without selecting them, except for "core" date segment fields.
    • The core date segment fields are segments.date, segments.week, segments.month, segments.quarter, and segments.year.
  • On fields of any message type except primitives (e.g.: Int64Value, StringValue, etc.)
  • On attributes of repeated fields of any message type except primitives (e.g.: Int64Value, StringValue, etc.)