# Query to get the latest version of each file in a directory -- no recursing.
SELECT DISTINCT ON (File.Name) Job.JobId,
                                  File.FileIndex
FROM Job
JOIN File ON Job.JobId = File.JobId
JOIN Path ON Path.PathId = File.PathId
JOIN Client ON Job.ClientId = Client.ClientId
WHERE Job.JobId IN (%s)
  AND Path.Path = '%s'
  AND Client.Name = '%s'
ORDER BY File.Name,
         Job.StartTime DESC,
         Job.JobId DESC
