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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:05:11+00:00 2026-06-09T08:05:11+00:00

I have 2 Tables — Table 1 is a master file and Table 2

  • 0

I have 2 Tables — Table 1 is a master file and Table 2 is an activity file.

The relationship is 1-to-Many.

I am producing a report and all I want to return is every master file row joined to only the last activity row for the related master id.

I am unsure on how to request the last activity row. My code below returns every activity row (rightfully so).

Thank you for your help.

    SELECT *
    FROM master_file AS master
    INNER JOIN activity_file AS activity ON activity.id = master.id
    ORDER BY master.display_name

The activity file has a column called entry_date. It is a date and time stamp recording every activity. I simply want to select the last entry_date.

For example:

Table 2 – Activity looks like this

ID ACTIVITY ENTRY_DATE
1 Update 2012-08-01 09:00:00
1 Edit 2012-08-01 13:45:15
3 Create 2012-07-15 10:09:52
3 Delete 2012-07-22 23:02:00
3 Add 2012-08-05 04:33:00
4 Edit 2012-08-03 15:12:00
  • 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-09T08:05:12+00:00Added an answer on June 9, 2026 at 8:05 am

    One standard way to solve this is to create an inline view that finds the last entry_date per ID.

    SELECT *
        FROM master_file AS master
        LEFT JOIN activity_file AS activity ON activity.id = master.id
        LEFT JOIN (select id , max(entry_date) entry_date
                    From activity_file 
                    group by id) last_activity
        ON activity_file.id = last_activity.id
          and  activity_file.entry_date= last_activity.entry_date
    
        ORDER BY master.display_name
    

    The one problem with this approach is that you may have more than one record with max(entry_date) for a given id. You’ll either need to have your business rules handle this (e.g. simply display more than one record for that case) or you’ll need to figure out a tie breaker. The last thing you want is to make it non-deterministic

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

Sidebar

Related Questions

I have tables Users, Widgets and Layouts. Users have many-to-many relationship with Widgets via
i have tables driver, cars and trailers they are all in relationship. and main
I have two tables, say Table A and Table B. I want to have
Say we have tables A, B, and C and then we want table Z
The dataset have tables and columns details got from the XML file.I want to
I have tables linked by FK, I query on the first table using entity
hi i have tables like this: Persons: person_id, name then i have many langauge
I have tables named: Posts_August_2011 Posts_September_2011 Posts_October_2011 Posts_November_2011 Posts_December_2011 Posts_January_2012 I want to create
I have tables, 1 called articles and another called links. I want to take
Hi i have tables like this : table entry : id | total_comments _____________________

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.