oracle - How to use logic to control what is selected in SQL -


i have following query

select   rel.firstobjectuuid,   rel.secondobjectuuid   component$ comp   inner join relationship$ rel on comp.objectuuid = rel.firstobjectuuid or comp.objectuuid = rel.secondobjectuuid   comp.componentid = '181814' 

does know how tell select firstobjectuuid when comp.objectuuid=rel.secondobjectuuid.
and select rel.secondobjectuuid when comp.objectuuid=rel.firstobjectuuid?

so basically, want return either firstobjectuuid or secondobjectuuid. 1 determined opposite of 1 used inner join between relationship$ , component$

edit: created fiddle explain awful explanation. http://sqlfiddle.com/#!2/4f655/1

(oracle doesn't seem working sqlfiddle, had make mysql)

but hope helps explain i'm trying do.

you can use left join twice bring in matches on different fields. coalesce() in select chooses particular object id.

select coalesce(rel1.firstobjectuuid, rel2.secondobjectuuid) component$ comp left join      relationship$ rel1      on comp.objectuuid = rel.firstobjectuuid  left join      relationshiptype$ reltype1      on reltype1.relationshiptypeid = rel1.typeid ,         reltype1.uuid = 'reltype:application_disposition_provides-is_provided_by_business_function_uuid' left join      relationship$ rel2       on comp.objectuuid = rel.secondobjectuuid left join      relationshiptype$ reltype2      on reltype2.relationshiptypeid = rel2.typeid ,         reltype2.uuid = 'reltype:application_disposition_provides-is_provided_by_business_function_uuid' comp.componentid = '181814' ,       (reltype1.uuid not null or reltype2.uuid not null); 

edit:

it little hard understand logic. perhaps arguments coalesce() should other way around?

select coalesce(rel2.secondobjectuuid, rel1.firstobjectuuid) 

that way, if second object matches, use it. otherwise use first object.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -