Skip to main content

Command Palette

Search for a command to run...

Where does QUALIFY fit in the order of execution in BigQuery?

Updated
1 min read
Where does QUALIFY fit in the order of execution in BigQuery?
C

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified

Here's an example of how QUALIFY fits into the order of execution in SQL.

In the BigQuery example below, we want to compute the second-to-last order_updated event for each order.

To do this, we filter to keep only the rows WHERE order_status = 'order_updated'.

We use there rows then to retrieve the event occurring second - sorting decreasingly by event_ts and partitioning by order_id, using QUALIFY.

The output is then ORDER BY the second_to_last_order_update_ts decreasingly.

Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.

Practical SQL

Part 1 of 50

Short, practical posts on SQL and BigQuery — from core language features to advanced query patterns. A reference for data practitioners at every level.

More from this blog

D

Datawise — SQL, BigQuery & Python for Data Engineers

205 posts

Data Engineer with a passion for transforming complex data landscapes into insightful stories. Here on my blog, I share insights, challenges, and the ever-evolving dance of technology and business.