AWS Certified Data Engineer Associate DEA-C01 Practice Question
An Amazon Redshift table named order_events contains multiple versions of each order identified by order_id. Each new version has a higher event_ts timestamp. You must write a single-pass SQL query that returns only the latest version of every order for a downstream ETL step. Which statement meets the requirement?
SELECT * FROM ( SELECT *, LEAD(event_ts) OVER (PARTITION BY order_id ORDER BY event_ts DESC) AS next_ts FROM order_events ) WHERE next_ts IS NULL;
SELECT DISTINCT ON (order_id) * FROM order_events ORDER BY event_ts DESC;
SELECT order_id, MAX(event_ts) AS event_ts FROM order_events GROUP BY order_id;
SELECT * FROM order_events QUALIFY ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY event_ts DESC) = 1;
Amazon Redshift supports the QUALIFY clause, which lets you filter the results of window functions in the same scan that produces them. Using ROW_NUMBER with PARTITION BY order_id and ORDER BY event_ts DESC ranks each version, and QUALIFY row_number = 1 keeps only the newest record per order. A simple GROUP BY with MAX(event_ts) cannot return the other column values without an additional join. LEAD requires a subquery or self-join, incurring another scan. DISTINCT ON is not supported in Redshift.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the QUALIFY clause in Amazon Redshift?
Open an interactive chat with Bash
Why can't MAX(event_ts) alone find the latest version of each order?
Open an interactive chat with Bash
What is the difference between ROW_NUMBER and LEAD in SQL?
Open an interactive chat with Bash
What is the QUALIFY clause in Amazon Redshift?
Open an interactive chat with Bash
How does ROW_NUMBER work with PARTITION BY in SQL?
Open an interactive chat with Bash
Why is SELECT DISTINCT ON unsupported in Redshift?
Open an interactive chat with Bash
AWS Certified Data Engineer Associate DEA-C01
Data Ingestion and Transformation
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .