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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:23:50+00:00 2026-05-27T22:23:50+00:00

there are two tables: TABLE cars id | date ———- 1 | 2012-01-04 2

  • 0

there are two tables:

TABLE cars

id | date
----------
1 | 2012-01-04
2 | 2012-01-04
3 | 2012-01-05

TABLE versions

id_car | year | author
-------------------------
1 | 2005 | John
1 | 2001 | Carl

2 | 2003 | Carl
2 | 2001 | John

3 | 2004 | Carl
3 | 2003 | John

I need to get all the information about cars with yesterday’s date (2012-01-04) and information about their latest version if author is Carl.

So in this example I need to get:
2 | 2012-01-04 | 2003 | Carl

  • 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-27T22:23:51+00:00Added an answer on May 27, 2026 at 10:23 pm

    You want an inner join:

    select
        c.id,
        c.date,
        v.year,
        v.author
    from
       cars c
       inner join versions v on
           c.id = v.id_car
       inner join (
            select 
                id_car, 
                max(year) as latestYear 
            from 
                versions 
            group by 
                id_car
        ) vmax on
           c.id = vmax.id_car
           and v.year = vmax.latestYear
    where
       v.author = 'Carl'
       and c.date = '2012-01-04'
    

    In this query, you’re saying, “Grab me everything from cars where the date is 2012-01-04 and then find everything in versions where the id_car column is equal to my id column in cars. Oh, and only give me anything from versions where the author is Carl, but only where the year of the car is equal to the greatest year of the car that’s available.”

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

Sidebar

Related Questions

One doubt in MSSQL. There are two tables in a databases. Table 1 named
I've two master tables Org & Item and then there's an OrgItem table.I have
We have two tables in a SQL Server 2005 database, A and B.There is
There are two tables: TABLE bills item_id | price c1 | 10000 m1 |
I have two tables in my database cars and car_types. cars table refers to
There are two tables: Product , ProductProperty ProductProperty is a table that stores the
I am confused about selecting two approaches. Scenario there are two tables Table 1
Thank you for your attention. There are two INNODB tables: Table authors id INT
There are two tables, Table A A_ID A_Field 1 blah1 2 blah2 3 blah3
There are two tables: employee and department. Employee table has columns: empid, deptid, employeename

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.