I have 3 queries which retrieves maximum value depending on a condition.
select max(to_number(substr(attr_value,9)))+1
from circ_inst inner
join circ_attr_settings
on circ_inst.circ_inst_id=circ_attr_settings.circ_inst_id
and val_attr_inst_id=1045
where circ_attr_settings.attr_value like 'IPANEMA-%'
select max(to_number(substr(attr_value,10)))+1
from circ_inst inner
join circ_attr_settings
on circ_inst.circ_inst_id=circ_attr_settings.circ_inst_id
and val_attr_inst_id=1045
where circ_attr_settings.attr_value like 'FIREWALL-%'
select max(to_number(substr(attr_value,16)))+1
from circ_inst
inner join circ_attr_settings
on circ_inst.circ_inst_id=circ_attr_settings.circ_inst_id
and val_attr_inst_id=1045
where circ_attr_settings.attr_value like 'LAYER2 SWITCH-%'
I would like to get the maximum number out of these 3 queries(if the results of the 3 queries are 6430, 6434 and 6418 respectively, then I would like to get the value “6434” which is the maximum of the three results.
I tried using max(query1,query2,query3) but not successful.
I think you can do this with one query:
Your joins all appear to be the same. The only difference is extracting the number. You can get the right start location by looking for a “-” in the value.