Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just need each 1 rec for each client, the most recent date 1

Status
Not open for further replies.

ljsmith91

Programmer
May 28, 2003
305
US
I have a simple SQL table that contains only a few fields. One field is "client", another is "my_date". There are a few other fields I need to pull too. But since there are so many dates for each client, I only want to output the most recent date for each client. I have tried both TOP and MAX(my_date) and I cannot seem to get it to do what I need. "my_date" is a datetime field. It still outputs everything. Do I need some sort of subquery ? As you can tell, I am no expert. Thanks for any help. -ljs

SELECT client, job, MAX(my_date), kbytes, filecount
FROM jobs_daily_summary
GROUP BY
client, job, kbytes, filecount
ORDER BY
client
 
Code:
SELECT a.*
FROM jobs_daily_summary a
INNER JOIN 
  (SELECT Client, MAX(my_date) AS MaxDate
  FROM jobs_daily_summary
  GROUP BY Client) b
ON a.client = b.client AND a.my_date = b.MaxDate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top