raziel3
Registered User.
- Local time
- Today, 01:26
- Joined
- Oct 5, 2017
- Messages
- 311
I'm trying to get the last/most recent cost of an item using this query.
I am getting duplicates in this query which I have managed to narrow down to the fact that returns are being recorded in the PurDetail like this
I tried adding another criteria
but still getting the duplicates.
Code:
SELECT Product.UPC, Product.PNAME, PurDetail.PurDate, PurDetail.CPU
FROM Product LEFT JOIN PurDetail ON Product.UPC = PurDetail.UPC
WHERE (((PurDetail.PurDate)=(SELECT MAX(PurDate)
FROM PurDetail As P2
WHERE P2.UPC = PurDetail.UPC
AND P2.PurDate <= Date())))
ORDER BY PurDetail.PurDate DESC;
I am getting duplicates in this query which I have managed to narrow down to the fact that returns are being recorded in the PurDetail like this
Code:
+--------------+-----------+----------+--------+-----------+----------------------+------+
| UPC | PurDate | Quantity | Cost | ZeroRated | ENTRYDATE | PID |
+--------------+-----------+----------+--------+-----------+----------------------+------+
| 040032125043 | 3/31/2022 | -3 | -10.67 | No | 5/12/2022 1:59:43 PM | 4036 | 'returned item
| 040032125043 | 3/31/2022 | 12 | 42.67 | No | 5/12/2022 2:00:39 PM | 4036 |
+--------------+-----------+----------+--------+-----------+----------------------+------+
I tried adding another criteria
Code:
And P2.Quantity >1