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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:34:58+00:00 2026-06-18T17:34:58+00:00

I have two MySQL tables. Table1: id name otherid Table2: id otherid time In

  • 0

I have two MySQL tables.
Table1:

id name otherid

Table2:

id otherid time

In each table, the “id” is a unique identifier for every row (and is also the primary key)
the “otherids” correspond between tables. There may be several (or 0) rows in table2 that have an otherid that corresponds to an otherid in table1. Table

For example,
Table 1:

id name otherid
1  bob  24
2  joe  326

Table 2:

id otherid time
4  326     2014-03-12 023:38:59
5  24      2013-02-11 22:05:21
6  24      2013-02-10 13:27:58

I am looking to fetch every row in table1, ordered by the most recent time of the rows in table2 that go with it according to the otherid.
In my example, this is the result I would be looking for:

id name time
2  joe  2014-03-12 023:38:59
1  bob  2013-02-11 22:05:21

This is because Joe has the most recent time from table2.

  • 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-18T17:35:00+00:00Added an answer on June 18, 2026 at 5:35 pm

    See below example :

    SELECT table1.*, max(table2.time) 
    FROM table1 
    INNER JOIN table2 ON table1.otherid = table2.otherid
    GROUP BY table2.otherid
    ORDER BY table2.id
    

    See SqlFiddle Demo

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

Sidebar

Related Questions

I have a mysql database with two tables: table1 (id, name, emailid) table2 (id,
I have the following two tables in my mysql database. Table Name: groups id
I have two tables in my MySQL database: CREATE TABLE table1 ( id int
I have two mysql tables that have the following structure: Table 1: ---ID---------NAME------- ---1-----
I have two tables in my mysql database. table1: shoutbox table2: users My tables
I have two mySQL tables as follows: [product] table P_id | Name | Quantity
I have two MySQL tables: attributes (attributeid, name) productsattributes (productid, attributeid, displayvalue) The required
I have two tables in a MySql DB: items id (char) name (varchar) description
I'm using PHP/MySql. If I have two tables (hypothetically) as follows: id name and
I have two MySQL tables, j and t, with a third normalising table, jt.

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.