Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Fastest Way to Get First Row of each partition

rgiljohannJan 19 2024

Hello, I am using Oracle 19c and have a very large partitioned table which is made up of JSON data. I am trying to extract just the first record of each partition using this query:

SELECT * FROM(
SELECT 
Column_1, Partition_Column, row_number()over ( partition by Partition_Column order by rownum) as rn
FROM table)
Where rn = '1'

Since my table is very large, it still takes a while. When I just grab the first row of the overall table:

Select * FROM table fetch first row only

This is almost instant.

I am just wondering if there is a faster way to grab the first record of each partition instead of using the row_number() function with the order by clause since I am not sorting out of the default order.

Below is an image of the data in the table. The two highlighted records are what I am trying to extract that first record for each partition. Please note, this is just an example, and there are a lot more records for each partition. As you can see, the highlighted records are a different format then the rest of the JSON in the table and act as reference points for all of the other data elements. That is why I am trying to pull those out separately.

This post has been answered by Jonathan Lewis on Jan 21 2024
Jump to Answer
Comments
Post Details
Added on Jan 19 2024
8 comments
7,327 views