Can anybody help me with the following SQL command please? I am not very experienced in SQL.
I have 2 tables:
Table Weighings with columns:
- WeighingId
- FileId
- MyDateTime
Table Files with columns:
- FileId
- Name
Table Weighings contains information when a specified file has been weighed. I need to make a list of last weighings of individual files, grouped by a file name. The final table would contain Weighing.Id, file name (File.Name) and second column when this file was weighed last time MAX(Weighings.MyDateTime).
There can be duplicate file names with different File.Id and I need to group all files with same name (so I can't group on File.FileId).
I was trying to use this code, but it doesn't work:
SELECT W.WeighingId AS WeighingId, MAX(W.MyDateTime) AS MaxMyDateTime
FROM Files F INNER JOIN Weighings W ON W.FileId = F.FileId
GROUP BY F.Name
ORDER BY F.Name
Thanks for your help, Petr