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.
I will explain you by giving example.

Suppose your A table is for `ORDERS` & B is for `PRODUCT DETAILS`

In your A table always one value will going to insert at a time.
But you cant have many products at a time in a single order 
So this is the general scenario where we need to get the most updated records from the database.

There are 2 ways :

`1.` On creation of order Insert one date into database & get updated records by using the date.

`2.` Auto incremented ID is the other option last ID will be your most updated records.

**But Most standard way is to use Date column in the database.**