sql - Select another attribute if the original attribute is NULL (Conditional select) -


how can achieve if want select attribute , if attribute null.

i know long way of this:

select val1 test_table val1 not null or select val2 test_table val1 null 

the bad solution if have long , complicated select need write twice...

eg:

select val1 test_table condition1 , condition2 , condition3 , val1 not null or select val2 test_table condition1 , condition2 , condition3 , val1 null 

so hope, maybe there shorter form this. anyway if or case in programming languages (i think).

any idea appreciated. first ide: inside select can shorten second select

select coalesce(val1, val2) test_table 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -