← All tutorials

Oracle SQL tutorial

Select the Current Coupon with ROW_NUMBER()

Retrieve the latest coupon record for each instrument in Oracle SQL using the ROW_NUMBER() window function.

Oracle SQLFinance · Securities · SQL
Oracle SQL Current Coupon tutorial thumbnail

About this tutorial

Return one current coupon per instrument

This tutorial shows how to rank coupon records within each instrument and keep only the most relevant row.

The key technique is the ROW_NUMBER() analytic function with PARTITION BY and ORDER BY, a pattern that is useful far beyond coupon data.

01

Partition by instrument

Create a separate ranking sequence for each instrument.

02

Order the coupon records

Define which coupon row should be treated as the latest or current one.

03

Keep one row

Filter the ranked result to ROW_NUMBER = 1 and return a single coupon per instrument.