thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Intermediate

ROW_NUMBER Function

A window function that assigns a unique sequential integer to rows within each partition according to the ORDER BY.

Definition

ROW_NUMBER never produces ties; rows with equal sort values get arbitrary but distinct numbers. A common pattern deduplicates records by keeping ROW_NUMBER() = 1 per business key ordered by latest timestamp.

Example

SELECT * FROM stg QUALIFY ROW_NUMBER() OVER (PARTITION BY id ORDER BY updated_at DESC) = 1;

Exam tip

To keep the latest version of each record, use ROW_NUMBER partitioned by key and ordered by timestamp DESC, then filter = 1.

Related terms