On the right track.  This will remove the duplicates and should be ANSI
compliant:

SELECT DISTINCT
cn,
date,
score

FROM
table

WHERE
date IN (
  SELECT MAX(date)
  FROM table
  GROUP BY cn
)

All the usual best practices smack-down lingo applies, including don't name
your database fields "date".

-Andy

-----Original Message-----
From: Mark Murphy [mailto:[EMAIL PROTECTED]
Sent: Thursday, May 27, 2004 5:25 PM
To: CF-Talk
Subject: Re: Return Most Recent Record PER CLIENT

It's tricky, but here's one way.  I know this works in Oracle.  I forget if
it works in SQL.

try this:
SELECT cn, date, score
FROM table
WHERE (cn, date) IN (
  SELECT cn, MAX(date) AS date
  FROM table
  GROUP BY cn
)

note that you could have a duplicate with this method if two dates were
exactly the same.

HTH.
-Mark
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to