Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4007496
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:38:21+00:00 2026-05-20T08:38:21+00:00

First I will show you example tables that my issue pertains to, then I

  • 0

First I will show you example tables that my issue pertains to, then I will ask the question.

[my_fruits]
fruit_name   |   fruit_id   | fruit_owner   |   fruit_timestamp
----------------------------------------------------------------
Banana       |   3          |  Timmy        |   3/4/11
Banana       |   3          |  Timmy        |   4/1/11
Banana       |   8          |  Timmy        |   5/2/11
Apple        |   4          |  Timmy        |   2/1/11
Apple        |   4          |  Roger        |   3/4/11

Now I want to run a query that only selects fruit_name, fruit_id, and fruit_owner values. I only want to get one row per fruit, and the way I want it to be decided is by the latest timestamp. For example the perfect query on this table would return:

[my_fruits]
fruit_name   |   fruit_id   | fruit_owner   |
----------------------------------------------
Banana       |   8          |  Timmy        |
Apple        |   4          |  Roger        | 

I tried the query:

select max(my_fruits.fruit_name) keep 
    (dense_rank last order by my_fruits.fruit_timestamp) fruit_name,
       my_fruits.fruit_id, my_fruits.fruit_owner 
from my_fruits 
group by my_fruits.fruit_id, my_fruits.fruit_owner

Now the issue with that is returns basically distinct fruit names, fruit ids, and fruit owners.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:38:22+00:00Added an answer on May 20, 2026 at 8:38 am

    For Oracle 9i+, use:

    SELECT x.fruit_name,
           x.fruit_id,
           x.fruit_owner
      FROM (SELECT mf.fruit_name,
                   mf.fruit_id,
                   mf.fruit_owner,
                   ROW_NUMBER() OVER (PARTITION BY mf.fruit_name
                                          ORDER BY mf.fruit_timestamp) AS rank
              FROM MY_FRUIT mf) x
     WHERE x.rank = 1
    

    Most databases will support using a self join on a derived table/inline view:

    SELECT x.fruit_name,
           x.fruit_id,
           x.fruit_owner
      FROM MY_FRUIT x
      JOIN (SELECT t.fruit_name,
                   MAX(t.fruit_timestamp) AS max_ts
              FROM MY_FRUIT t
          GROUP BY t.fruit_name) y ON y.fruit_name = x.fruit_name
                                  AND y.max_ts = x.fruit_timestamp
    

    However, this will return duplicates if there are 2+ fruit_name records with the same timestamp value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing my first project that will use autoconf and teaching it to
For example, will the first piece of code perform a full search twice, or
First of all, let's define a few tables: Users table will store information about
So this question will get technical – eventually – but first check out Hanselminutes
I am trying to write a JavaScript function that will return its first argument(function)
Which command will executed first,If a stored procedure have individual multiple select commands;
With :limit in query, I will get first N records. What is the easiest
First of all, I will admit I am a novice to web services, although
PHP (among others) will execute the deepest function first, working its way out. For
I am preparing to use continuous integration for the first time. I will be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.