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: 
A typical way to do this is to use the ANSI standard `row_number()` function. Here is a sketch of what the query might look like:

```
select *
from a left join
     (select b.*, row_number() over (partition by b.aid order by b.date desc) as seqnum
      from b
     ) b
     on a.aid = b.aid and b.seqnum = 1;

```

You can also approach this with aggregation:

```
select *
from a left join
     b
     on a.aid = b.aid join
     (select b.aid, max(b.date) as maxdate
      from b
     ) bmax
     on b.aid = b.aid and b.date = bmax.date;

```
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.