Good Afternoon,
I'm trying to build a simple inventory system and i wish i could have a query able to select the last entry for each product (component ; ref) and also the one just before the last one for each product (to compare).
This is what i have so far :
My query so far is :
SELECT u1.*
FROM $usertable u1
JOIN (
SELECT component, ref, MAX(date) date
FROM $usertable
GROUP BY component, ref
) u2
USING(component, ref, date) ORDER BY component ASC, ref ASC
Can you please help me to figure out the solution ?