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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:18:37+00:00 2026-06-11T16:18:37+00:00

I am using a Derby database. I have a table like this: TB_ORDERS BUYER_NAME

  • 0

I am using a Derby database.

I have a table like this:

TB_ORDERS
BUYER_NAME  DATE_CREATED    OTHER_COLLUMS ......
---------------------------------------------
 DAVID       2012-09-01         ----
 PETER       2012-09-14         ----
 DAVID       2012-09-05         ----
 PETER       2012-09-02         ----
 DAVID       2012-08-15         ----
 MARY        2012-09-02         ----
 MARY        2012-09-15         ----

I am trying to get a result grouped by BUYER_NAME where each group should be ordered by DATE_CREATED and finally everything ordered by the group’s most recent date, like this:

MARY    2012-09-15
MARY    2012-09-12
PETER   2012-09-14
PETER   2012-09-02
DAVID   2012-09-05
DAVID   2012-09-01
DAVID   2012-08-15

As you can see, the Mary’s Group has the most recent date_created so it is placed on top.
Then we get Peter’s group on second place (note that Peter’s group has a date “09-14” higher then one date on Mary’s group “09-12” however, Peter’s group is placed after Mary’s group as every thing should be ordered by the group’s most recent date.

I have tried every thing I know with no success. The closest I got was:

Select date_created, buyer_name 
From ORDERS 
Order By buyer_name,date_created Desc;

However, the groups are not ordered by the most recent group date.

Should I do that in my code or is there a better way?

  • 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-11T16:18:39+00:00Added an answer on June 11, 2026 at 4:18 pm

    This query will bring you the most recent date_created of each buyer_name, together with the result set that you already had. If you include this new column in your Order By clause it should do the trick:

    Select o.date_created, o.buyer_name,
           (select max(date_created) from orders where buyer_name = o.buyer_name) as most_recent_date
    From ORDERS o
    Order By most_recent_date, o.buyer_name, o.date_created Desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Derby database with Java and Eclipse. I have a table which
I'm using Netbeans and Derby database. I would like to insert to a table
I would like to create an in-memory database for testing purposes using Derby/JavaDB. I
I have (java) code that creates and populates tables in a derby database, using
I have been developing a Java application using J2EE and a Derby database. My
I have created a JavaDB(Derby) database using Netbeans 7.1 on my mac and I
I'd like to have a peek at Derby's database log; I don't mean the
I am using Derby database. I wrote this query: InputStream is = new java.io.ByteArrayInputStream(BYTES);
I have a problem with querying Derby database. I am using Hibernate with JPA.
I'm using derby as an embedded database. Furthermore, I'm using it's in-memory database option

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.