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 

Find first and last row...

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


Joined: 22 Jul 2004
Posts: 18
Topics: 8

PostPosted: Tue Sep 21, 2004 11:06 am    Post subject: Find first and last row... Reply with quote

It seems simple enough.
Create a SPUFI that can return (and eventually update) the first and the last row for a given criteria.
I've looked for somekind of MIN / MAX feature, but haven't been able to locate any.
Any suggestions ?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Sep 21, 2004 11:32 am    Post subject: Reply with quote

KM,

Try the following sql.

Code:

UPDATE TABLE                                       
   SET COL1 = 'MIN UPDATE VALUE'                           
  WHERE COL2 = (SELECT MIN(COL2) FROM TABLE)     
   ;               

UPDATE TABLE                                       
   SET COL1 = 'MAX UPDATE VALUE'                           
  WHERE COL2 = (SELECT MAX(COL2) FROM TABLE)     
   ;




Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
KM
Beginner


Joined: 22 Jul 2004
Posts: 18
Topics: 8

PostPosted: Tue Sep 21, 2004 1:32 pm    Post subject: Reply with quote

Quick reply. Much appreciated !
It gives me an idea, yes, but before any update can take place I need to be able to pull the first and the last row:

123 AAA
123 BBB
123 CCC
123 DDD
123 EEE
123 FFF

How do I pull just AAA and FFF ?. Bear in mind that there could be more than six rows.
After that, I will update these rows....
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Sep 21, 2004 1:40 pm    Post subject: Reply with quote

Km,


Code:

COL1  COL2
123   AAA
123   BBB
123   CCC
123   DDD
123   EEE
123   FFF


The following sql will give you 'AAA'

Code:

 SELECT MIN(COL2)
   FROM TABLE
      ;


The following sql will give you 'FFF'

Code:

 SELECT MAX(COL2)
   FROM TABLE
      ;


If you want the other column information then you need to change the sql to the following

Code:

 SELECT *
   FROM TABLE
  where COL2 = (SELECT MIN(COL2)
                  FROM TABLE)
      ;

 SELECT *
   FROM TABLE
  where COL2 = (SELECT MAX(COL2)
                  FROM TABLE)
      ;



Hope this helps...

Cheers

kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
KM
Beginner


Joined: 22 Jul 2004
Posts: 18
Topics: 8

PostPosted: Tue Sep 21, 2004 1:57 pm    Post subject: Reply with quote

Excellent.
Strange how two lines of code can make you happy. You made my day !
Thanks again !
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