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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:18:03+00:00 2026-05-11T18:18:03+00:00

Im having a moment, what i want to do is really simple and i

  • 0

Im having a moment, what i want to do is really simple and i think im just looking at the wrong solution. I want to simply return a table that is sorted based on a datestamp of a related table.

ie:

Table 1:
200   MyStuff   OK
201   Other     Why
202   Flat      So

Table 2:
1  200  5/12/2009  MyValue1
2  200  5/11/2009  MyValue2
3  201  7/10/2009  MyValue3
4  201  7/08/2009  MyValue4

I want the to return the first table sorted based on the dates in the second table, so my result should be

201  Other   Why
200  MyStuff OK
202  Flat    So

I have tried doing an inner join, but what i select distinct i have to include the date from the second table that im sorting on, thus i end up with duplicate pk’s on the return table.

Please help me understand my rookie mistake here.

  • 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-11T18:18:03+00:00Added an answer on May 11, 2026 at 6:18 pm

    Since you can have multiple rows in Table2 for every row in Table1, you’ll have to decide on how to handle the dates as far as sorting.

    Let’s say you want to sort on the maximum date stamp, you’d do something like:

    select table1.*, t2.max_ds
    from table1 
    inner join (select id, max(datestamp) as max_ds from table2 group by id) t2
    on t2.id = table1.id
    order by t2.max_ds
    

    You’ll obviously have to add some null handling and whatnot, but that should get you started.

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

Sidebar

Related Questions

Perhaps I'm having a Post-Ballmer-Peak Moment . I'm hoping that someone can help point
I'm having an issue at the moment that I've been doing alot of searching
At the moment I am in the following /public_html/v3/football/admin/new.php Inside that new.php, i want
I'm having a Friday afternoon moment, and I'm really struggling to sort these items
Maybe I am having a moment of 'afternoon', but can anyone explain why I
I'm having a blonde moment, here is my problem: Break down: I have an
so I am having a noob moment here, I haven't ever used the command
Having a slight Javascript issue at the moment, I am hoping to have the
I am having a lot of trouble with Reflection in C# at the moment.
I'm starting a new Silverlight project at the moment, and I'm having issues where

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.