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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:01:48+00:00 2026-06-15T18:01:48+00:00

We have two table where where table A and table B need to be

  • 0

We have two table where where table A and table B need to be join. Relationship between table A and B is one to many. We can join now using this LEFT JOIN tableB on tableA.aID=tableB.aID. We would like to ensure only one record is join on table B and that is the latest record only. We now get more then one record.

SELECT student.*

FROM   student
       LEFT JOIN (SELECT B1.*
                  FROM medicalRecord AS B1
                         LEFT JOIN medicalRecord AS B2
                                ON B1.studentID = B2.studentID
                                   AND B1.checkUpDate< B2.checkUpDate
                  WHERE  B2.studentID IS NULL) AS b
              ON ( student.studentID = medicalRecord.studentID)

Where student.studentID=45
  • 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-15T18:01:50+00:00Added an answer on June 15, 2026 at 6:01 pm

    Let us assume you want to get only the record from the child table with the highest value in the val column. You could use:

    SELECT a.*,
           b.*
    FROM   a
           LEFT JOIN (SELECT B1.*
                      FROM   b AS B1
                             LEFT JOIN b AS B2
                                    ON B1.aID = B2.aID
                                       AND B1.val < B2.val
                      WHERE  B2.aID IS NULL) AS b
                  ON ( a.aID = b.aID )  
    

    The idea is to use a subquery to filter the table for the records with the greatest values in the val column, then to join on that.

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

Sidebar

Related Questions

I have a many-to-many relationship between two objects with a join table. I need
I have two tables that are connected via a join table in a many-to-many
I have two tables in a one to many relationship. (products and qty break
I have two models: Bar HABTM Foo. Now I have bars_foos join table with
I have two tables: Item and ItemHistory with a one to many relationship. I
I have two tables, which I need to join by one column and is
How can I join two cascading many-to-many relationships ? I have 5 tables :
i have the following query to list the employees of two table. i need
I have a database two tables and a linking table that I need a
I have xpath page.search(//table[@class='campaign']//table) which returns two tables. I need to choose only first

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.