CASE statement in Oracle - depending on 2 columns (not 1) multiple -


i have such table may have table_item_definition:

╔═════════════════════╦══════════╦═══════════╗ ║        name         ║ language ║ object_id ║ ╠═════════════════════╬══════════╬═══════════╣ ║ name in english  ║ en       ║ 123459098 ║ ║ mon nom en espagnol ║ sp       ║ 123459098 ║ ║ name in klingon  ║ kl       ║ 123459098 ║ ╚═════════════════════╩══════════╩═══════════╝ 

when showing object after query: intend english name if exists, otherwise spanish 1 if exists, otherwise klingon..i.e. i'll show 1 name exists first acc criteria.

you use coalesce , self join:

select m.*, coalesce(t1.name, t2.name, t3.name) result main_object_table m left join table_item_definition t1   on m.object_id = t1.object_id   , t1.language = 'en' left join table_item_definition t2   on m.object_id = t2.object_id   , t2.language = 'sp' left join table_item_definition t3   on m.object_id = t3.object_id   , t3.language = 'kl' m.object_id = 123459098; 

livedemo


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -