MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help regarding delete query

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
dubasir
Beginner


Joined: 13 Dec 2004
Posts: 20
Topics: 9

PostPosted: Wed Sep 23, 2009 4:21 am    Post subject: Help regarding delete query Reply with quote

I have a requirement where I have to select maximum effective date <= current _date for a given group and then delete the rows for the group with
effective date < maximum effective date obtained in the previous query.

Please help how to get the required output using a single delete statement.
Code:

SELECT DISTINCT A,
                B,
                C,
                D,
                E,
                F,     
                G,
                MAX(DATE_EFF)
                FROM Table1
WHERE DATE_EFF  <=   CURRENT_DATE
GROUP BY A,B,C,D,E,F,G



Delete the records for a given A,B,C,D,E,F,G and DATE_EFF < MAX(DATE_EFF) obtained in the previous query
Code:
 
DELETE FROM Table1
 WHERE  A           =   &A
   AND  B           =   &B
   AND  C           =   &C
   AND  D           =   &D
   AND  E           =   &E
   AND  F           =   &F
   AND  G           =   &G
   AND  DATE_EFF     <    &MAX(DATE_EFF)
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Thu Sep 24, 2009 7:25 am    Post subject: Reply with quote

The OP used this solution (provided on another board):
Code:

delete from table1 O
where date_eff < (select max(I.date_eff) from table1 I
      where I.A = O.A
        and I.B = O.B
        and I.C=O.C
         ...
        and I.G = O.G)

_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
RonB
Beginner


Joined: 02 Dec 2002
Posts: 93
Topics: 0
Location: Orlando, FL

PostPosted: Thu Sep 24, 2009 12:27 pm    Post subject: Reply with quote

dbzTHEdinosauer wrote:
The OP used this solution (provided on another board):
Code:

delete from table1 O
where date_eff < (select max(I.date_eff) from table1 I
      where I.A = O.A
        and I.B = O.B
        and I.C=O.C
         ...
        and I.G = O.G)

If that is the implementation that the OP actually used, then it ( obviously) didn't satisfy his originally posted requirements, which stated that the max(date_eff) used as a predicate for the delete must be <= current_date.
_________________
A computer once beat me at chess, but it was no match for me at kick boxing.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group