#
# "WHERE JobId > 0" is a dummy where clause,
#                   to make it easier to extend the filter
#                   (all filters starts with "AND ...")
# JOIN with Media is required for filter to Media.Volumename.
#

SELECT DISTINCT Job.JobId, Job.Job, Job.Name, Job.PurgedFiles, Job.Type, Job.Level,
Job.ClientId, Client.Name as Client, Job.JobStatus, Job.SchedTime, Job.StartTime,
Job.EndTime, Job.RealEndTime, Job.JobTDate, Job.VolSessionId, Job.VolSessionTime,
Job.JobFiles, Job.JobBytes, Job.JobErrors, Job.JobMissingFiles, Job.PoolId,
Pool.Name as PoolName, Job.PriorJobId, Job.FileSetId, FileSet.FileSet
FROM Job
LEFT JOIN Client ON Client.ClientId=Job.ClientId
LEFT JOIN Pool ON Pool.PoolId=Job.PoolId
LEFT JOIN JobMedia ON JobMedia.JobId=Job.JobId
LEFT JOIN Media ON JobMedia.MediaId=Media.MediaId
LEFT JOIN FileSet ON FileSet.FileSetId=Job.FileSetId
WHERE Job.JobId > 0
%s
ORDER BY StartTime%s;
