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

  • Home
  • SEARCH
  • 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 8225295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:22:08+00:00 2026-06-07T15:22:08+00:00

I’m quite new to Oracle and I recently ran into a problem : I

  • 0

I’m quite new to Oracle and I recently ran into a problem :

I have a table with the following columns : person_id, account_login, add_date.

person_id | account_login | add_date
----------|---------------|------------
1         | user1         | 2012-07-10
1         | user2         | 2012-07-09
2         | user3         | 2012-07-05
2         | user4         | 2012-07-04

A person can have multiple account_logins. For every person, I want to fetch the oldest account_login :

person_id | account_login | add_date
----------|---------------|------------
1         | user2         | 2012-07-09
2         | user4         | 2012-07-04

So what I did was :

select
  person_id,
  MAX(account_login) KEEP (DENSE_RANK FIRST ORDER BY add_date)
from
  table
group by
  person_id;

I get exactly the result I want, but I think the syntax of my query is far from good.. Oracle forces me to use an aggregate function and I used MAX() or MIN() knowing that it’s completely senseless..

Is there a way to write the query better than this? (Oracle 11g)

  • 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-06-07T15:22:10+00:00Added an answer on June 7, 2026 at 3:22 pm

    You can use DENSE_RANK as an analytic alone, and select from the resulting query:

    SELECT person_id, account_login, add_date
      FROM (SELECT table.*
                 , DENSE_RANK() OVER (PARTITION BY person_id ORDER BY add_date) rnk
             FROM table)
     WHERE rnk = 1;
    

    Not sure which version you consider more elegant. It also does not address what to do if you have two accounts created on the same date for a particular person_id. If you’ve also got a time component in your add_date then you should be okay. If ties are likely, perhaps ROW_NUMBER() would give you a more desirable outcome.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have two tables with like below codes: Table: Accounts id | username |
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

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.