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 77145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:47:04+00:00 2026-05-10T20:47:04+00:00

This is something that comes up so often I almost stopped thinking about it

  • 0

This is something that comes up so often I almost stopped thinking about it but I’m almost certain that I’m not doing this the best way.

The question: Suppose you have the following table

CREATE TABLE TEST_TABLE (   ID          INTEGER,   TEST_VALUE  NUMBER,   UPDATED     DATE,   FOREIGN_KEY INTEGER ); 

What is the best way to select the TEST_VALUE associated with the most recently updated row where FOREIGN_KEY = 10?

EDIT: Let’s make this more interesting as the answers below simply go with my method of sorting and then selecting the top row. Not bad but for large returns the order by would kill performance. So bonus points: how to do it in a scalable manner (ie without the unnecessary order by).

  • 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. 2026-05-10T20:47:04+00:00Added an answer on May 10, 2026 at 8:47 pm

    Analytic functions are your friends

    SQL> select * from test_table;          ID TEST_VALUE UPDATED   FOREIGN_KEY ---------- ---------- --------- -----------          1         10 12-NOV-08          10          2         20 11-NOV-08          10  SQL> ed Wrote file afiedt.buf    1* select * from test_table SQL> ed Wrote file afiedt.buf    1  select max( test_value ) keep (dense_rank last order by updated)   2  from test_table   3* where foreign_key = 10 SQL> /  MAX(TEST_VALUE)KEEP(DENSE_RANKLASTORDERBYUPDATED) -------------------------------------------------                                                10 

    You can also extend that to get the information for the entire row

    SQL> ed Wrote file afiedt.buf    1  select max( id ) keep (dense_rank last order by updated) id,   2         max( test_value ) keep (dense_rank last order by updated) test_value ,   3         max( updated) keep (dense_rank last order by updated) updated   4  from test_table   5* where foreign_key = 10 SQL> /          ID TEST_VALUE UPDATED ---------- ---------- ---------          1         10 12-NOV-08 

    And analytic approaches are generally pretty darned efficient.

    I should also point out that analytic functions are relatively new, so if you are on something earlier than 9.0.1, this may not work. That’s not a huge population any more, but there are always a few folks stuck on old versions.

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, to send the screenshot, you can use… May 11, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer I figured it out: window.nativeWindow.x = (Screen.mainScreen.bounds.width - window.width)/2; window.nativeWindow.y… May 11, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer Ok I solved my problem. It was not Message.WriteMessage that… May 11, 2026 at 11:41 pm

Related Questions

I'm working on keyboard input for a very basic kernel that I'm developing and
Before you answer this I have never developed anything popular enough to attain high
Here is the scenario 1. I have a table called items, inside the table
I am trying to understand if I really have any case for using git/mercurial.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.