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.
See below example :
See SqlFiddle Demo