Good afternoon everyone! I've been working on this for two days and have no clue why this isn't working. I've tried several different ways to get the correct results and I either have too many returns or 0. I have two tables for tracking assets with the following layout:

Table: AssetManagment

```
id | serial | idcode
---|--------|-------
1  | 123    | 4
2  | 1234   | 4

```

Table: AssetManagement\_History

```
id | rowID  | action    | occurred
---|--------|-----------|-------------
1  | 1      | shipping  | 2014-04-01
2  | 1      | stocked   | 2014-04-02
3  | 1      | installed | 2014-04-03
4  | 2      | stocked   | 2014-04-04

```

In this example, the AssetManagement\_History.rowID relates to AssetManagment.id so you can see there are three history details for the first asset and only 1 for the second asset. I need to have returned all the assets where the *last* action corresponds to 'stocked' or 'restocked' - so only the second asset should be returned. Here's several mySQL statements I've tried:

```
SELECT tblASSET.id,tblASSET.serial
FROM AssetManagement tblASSET
INNER JOIN 
(SELECT occurred,max(id) id 
FROM AssetManagement_History GROUP BY occurred) tblAH ON tblASSET.id = tblAH.rowID
WHERE tblASSET.idcode='4' AND tblAH.action IN ('stocked','restocked')

```

another attempt:

```
SELECT tblASSET.id,tblASSET.serial
FROM AssetManagement tblASSET
INNER JOIN 
(SELECT max(rowID) rowID 
FROM AssetManagement_History GROUP BY occurred) tblAH ON tblAH.rowID = tblASSET.id
WHERE tblASSET.idcode='4'

```

I have several others, but they didn't work either. Any help would greatly be appreciated!

Thanks,
Dave