Available in versions: Dev (3.22)

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

IS_FIRST

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The IS_FIRST window function allows for checking if a row is among the first N rows within a window using ROW_NUMBER semantics.

For example:

SELECT
  ID,
  is_first(2) OVER (ORDER BY ID)
FROM
  BOOK;
create.select(
         BOOK.ID,
         isFirst(2).over(orderBy(BOOK.ID)))
     .from(BOOK)
     .fetch();

Producing:

+----+----------+
| id | is_first |
+----+----------+
|  1 | true     |
|  2 | true     |
|  3 | false    |
|  4 | false    |
+----+----------+

Dialect support

This example using jOOQ:

isFirst(2).over(orderBy(BOOK.ID))

Translates to the following dialect specific expressions:

Aurora Postgres, BigQuery, ClickHouse, CockroachDB, DB2, Databricks, DuckDB, Exasol, Firebird, H2, Hana, Informix, MariaDB, MemSQL, MySQL, Oracle, Postgres, Redshift, SQLDataWarehouse, SQLServer, SQLite, Snowflake, Sybase, Teradata, Trino, Vertica, YugabyteDB

row_number() OVER (ORDER BY BOOK.ID) <= 2

ASE, Access, Aurora MySQL, HSQLDB, Spanner

/* UNSUPPORTED */
Generated with jOOQ 3.22. Support in older jOOQ versions may differ. Translate your own SQL on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo