Friday, February 24, 2012

How to do Minof max and maxof min Calculation in SQL


Hi all,
I have two tables say A and B. and i have the following fields in the two tables
A B
vc_low(say 32) min_vc(say 35)
What is the query to get the MAX of these two fields
It should be like max(vc_low,min_vc),....But i dont know how to form a querry in SQL..
Can any one help me .........

Thanks in AdvanceYou can use CASE clause. From your subject and message i've drafted below example:
create table test1 (id1 int)
insert into test1 values(1)
insert into test1 values(2)
create table test2 (id2 int)
insert into test2 values(11)
insert into test2 values(12)
select 'max value' = case when min(test1.id1) > min(test2.id2) then min(test1.id1) when min(test2.id2) > min(test1.id1) then min(test2.id2) END from test1,test2
The result of the above query will 11
hope the above helps you.
-srikanthr

No comments:

Post a Comment