DELETE all records based the max date

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

DELETE all records based the max date

Post by sal21 »

I need to delete all records based CF and max date and maintain the newest....

for example CF=A007, delete all and maintain the only records with date 19/08/1974

naturally if CF have only a records maintain and not delete...

hope you understand me.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78604
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DELETE all records based the max date

Post by HansV »

The table contains 4 date fields: DTIST, DCESS, DTAGG and AL.
Which field should we use?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: DELETE all records based the max date

Post by sal21 »

HansV wrote:
23 Oct 2023, 09:46
The table contains 4 date fields: DTIST, DCESS, DTAGG and AL.
Which field should we use?
Sorry....
DCESS

User avatar
HansV
Administrator
Posts: 78604
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DELETE all records based the max date

Post by HansV »

SQL = "DELETE DCESS FROM HANS WHERE CF='A007' AND DCESS<(SELECT Max(DCESS) FROM HANS WHERE CF='A007')"
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: DELETE all records based the max date

Post by sal21 »

HansV wrote:
23 Oct 2023, 11:21
SQL = "DELETE DCESS FROM HANS WHERE CF='A007' AND DCESS<(SELECT Max(DCESS) FROM HANS WHERE CF='A007')"
But this delete all revordeset, entire raw?

User avatar
HansV
Administrator
Posts: 78604
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DELETE all records based the max date

Post by HansV »

It deletes entire records where CF equals 'A007' and DCESS is less than the maximum value for DCESS where CF equals 'A007'.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

Re: DELETE all records based the max date

Post by sal21 »

HansV wrote:
23 Oct 2023, 11:52
It deletes entire records where CF equals 'A007' and DCESS is less than the maximum value for DCESS where CF equals 'A007'.
:clapping: