Discussions
Join the NetSuite community to innovate, connect, and discover what’s next.
SuiteWorld brings thousands of innovators, builders, and leaders together to learn, connect, and shape what’s next. This October, explore how to build a stronger foundation for growth through inspiring keynotes, major product reveals, hands-on sessions, and unforgettable moments—all in one place for our biggest event of the year. Register now
SQL Essentials: KEEP Function Explained
Overview
The KEEP() function in SQL is used in conjunction with aggregate functions to return specific values from a group of rows based on a defined ordering. In simpler terms, it allows you to extract a particular value (such as the first or last entry) within a grouped dataset, according to a specified sort order. This is particularly useful when you need to retrieve the most recent or earliest record in a set, like identifying the latest transaction for each customer.
Understanding the Syntax
The general syntax for using the KEEP() function with an aggregate function is:
AGGREGATE_FUNCTION(column_name) KEEP (DENSE_RANK FIRST | LAST ORDER BY column_name)
Learn how to Refer A Member | Earn the Answer Accepter Badge | Be the Content Creator of the Quarter | Vote for the content you want to see!
