> I have a table which contains all the orders from all the clients :
>
> #ORDER
> #CLIENT
> DateTimeOrder
>
> I need to keep only the more recent order from each client.
>
> Any Idea how to do that without using DECLARE Cursor ?
This will give you the records you want to keep:
SELECT * FROM MyTable T1 WHERE NOT EXISTS +
(SELECT * FROM MyTable T2 +
WHERE T2.#ORDER = T1.#ORDER AND +
T2.#CLIENT = T1.#CLIENT AND +
T2.DateTimeOrder > T1.DateTimeOrder)
And conversely, this will remove from the table all the records you want to
discard:
DELETE FROM MyTable T1 WHERE EXISTS +
(SELECT * FROM MyTable T2 +
WHERE T2.#ORDER = T1.#ORDER AND +
T2.#CLIENT = T1.#CLIENT AND +
T2.DateTimeOrder > T1.DateTimeOrder)
--
Larry
================================================
TO SEE MESSAGE POSTING GUIDELINES:
Send a plain text email to [EMAIL PROTECTED]
In the message body, put just two words: INTRO rbase-l
================================================
TO UNSUBSCRIBE: send a plain text email to [EMAIL PROTECTED]
In the message body, put just two words: UNSUBSCRIBE rbase-l
================================================
TO SEARCH ARCHIVES:
http://www.mail-archive.com/rbase-l%40sonetmail.com/