IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Scalar function say MAX in where clause of a SELECT querY


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mfguy

New User


Joined: 31 Jul 2003
Posts: 4

PostPosted: Thu Jul 31, 2003 11:19 am
Reply with quote

HI
could anypone please guide on this.
Can we use the scalar function say MAX in the where clause of a SELECT query to see a user with maximum values ?(or) we have to go for subquery with the inner query selecting the max value
i.e
select user from table
where value in
( select max(value) from table
where user='xxx')
Just have a doubt on the first part of the question.Help appreciated
Thanks
mfguy
Back to top
View user's profile Send private message
tsurya

New User


Joined: 01 Aug 2003
Posts: 1
Location: Chennai

PostPosted: Fri Aug 01, 2003 12:06 pm
Reply with quote

Hi
U can use scalar function MAX in Where clause.

select EMP-NAME from EMP-table
where SALARY=
( select max(SALARY) from EMP-table
where DEPT-CD='xxx') ;

Thanks,
Surya.
Back to top
View user's profile Send private message
mdtendulkar

Active User


Joined: 29 Jul 2003
Posts: 237
Location: USA

PostPosted: Fri Aug 01, 2003 6:42 pm
Reply with quote

Hello,

Similarly you can use this subquery to retrieve the nth max or min value for the column also.


Select A.sal from emp A
where 2 = (select count (distinct B.sal) from emp B where B.sal >= A.sal)

Here, 2nd max salary will be retrieved.

Similar results will be obtained from following query

select max(salary) from employee where
salary < (select max(salary) from employee)


Hope this will help you.

Regards

Mayuresh
Back to top
View user's profile Send private message
vinoth

New User


Joined: 06 Aug 2003
Posts: 1
Location: chennai

PostPosted: Wed Aug 06, 2003 4:02 pm
Reply with quote

i want full sql queries

please guide me us.

waiting for ur reply

regards
vinoth
Back to top
View user's profile Send private message
mdtendulkar

Active User


Joined: 29 Jul 2003
Posts: 237
Location: USA

PostPosted: Thu Sep 11, 2003 9:09 am
Reply with quote

Hello,

Please tell your requirement in detail.


Regards

Mayuresh
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts COBOL 6.4 - User Defined Function nee... COBOL Programming 6
No new posts Inserting into table while open selec... DB2 1
No new posts RC query -Time column CA Products 3
No new posts Calling an Open C library function in... CICS 1
Search our Forums:

Back to Top