I have two tables,
jobcli
- client_id
- job_id
jobs
- job_id
- jobTitle
- startDate
- projectmgr
What I am having trouble with is to display client_id, job_id, jobTitle, startDate, and projectmgr in a query, where the results are grouped by client_id and have max of date.
So far I can get a list that's groupped by client_id with their corresponding max(startDate).
SELECT client_id, MAX(startDate) AS LastJob FROM jobcli INNER JOIN jobs ON jobcli.job_id = dbo.jobs.id GROUP BY jobcli.client_id
This query only returns 2 fields, client_id and LastJob, but I also want to display job_id, projectmrg and title for the last job.
This scenario is for a SQL server 2005. Thanks for your help.