Question: I have two tables, A and B. For a particular value in A in a particular column there will be multiple rows in B that correspond to it. I want to extract the info from B, but not all the rows but just the most recent.

What is the eastiest way to do this?

Thanks

Answer: 
Assuming `B.id` is `AUTO INCREMENTED` and `B.a_id` references A, you can

```
SELECT B.id,B.a_id,B.data FROM A
JOIN B
ON B.a_id = A.id
WHERE B.id IN (
  SELECT MAX(B.id)
  FROM B
  GROUP BY B.a_id  
)

```

See [SQLFiddle](http://sqlfiddle.com/#!12/2af88/6). I'm assuming PostgreSQL here, but I'm sure you can adapt accordingly.
If the rows are only added and not updated and the IDs are not recycled numbers, then you can selects the record from B with highest number.

If you are able to edit the schema, then put last lastUpdatedTime column into B and select according to column.