I'm new to Oracle and having knowledge of MS SQL. I'm trying to get a phone number depending upon the user_id from Table2 and here is the business logic:
Case1: if a single match is found in
Table1then get it's respective toll free number fromTable2Case2: if no match is found in
Table1then get the default toll free number fromTable2Case3: if an multiple match is found in
Table1then for all thoseassigned_care_levelsget theCarevalue fromTable2ordered byascordescand select the top row phone number.
I wrote the following query which works fine when I run it individually. However, when I cobine it using the if else statements I'm getting the following error ERROR: ORA-00907: missing right parenthesis. Here is my code:
if ((select count(distinct care_level) from Table1 where user_id = '100') > 0)
select phone from Table2 where care_level in (select distinct care_level from Table1 where user_id = '100')
and rownum = 1
order by care_level asc
else if((select count(distinct care_level) from Table1 where user_id = '100') = 0)
select phone from Table2 where care_level = 'default'
EDIT: ( AS SIngle SQL)