Hello Experts Exchange
I have a MySQL query that gives me all the stock count records from the database.
I want to select the latest records for the stock items selected.
I have attached a CSV file of example data.
This is my current query;
Select dl.area, dl.name as location, si.id, si.name as item_ref, ssi.Updated_at,ssi.count
From data_location as dl
inner join stk_stocktake_header ssh on dl.id = ssh.location_id
inner join stk_stocktake_item ssi on ssi.stocktake_header_id = ssh.id
inner join stk_item as si on si.id = ssi.stk_item_id
inner join stk_product as sp on si.stk_product_id = sp.id
inner join stk_stock_ref as ssr on sp.stk_stock_ref_id = ssr.id
Where dl.area in ('Area 1 Scotland')
and dl.name in ('Callander - 030')
and si.id in (11391,11392)
order by si.id,ssi.Updated_at desc
The records I want from the example data are;
Area 1 Scotland Callander - 030 11391 PLU3941 Diary-2017 Corporate Pink 2016-10-27 09:09:20 12.00000
Area 1 Scotland Callander - 030 11392 PLU3942 Diary-2017 Corporate Turquoise 2016-10-27 09:09:20 8.00000
How do I change my SQL to only select the latest records for each item?