sql - Union null in Oracle -


i'm trying combine 2 querys in oracle, lines have same value expect 1 field.

ex:

select name, age, email, date table_a name = 'joao' , flag = '0' union select name, age, email, date table_a name = 'joao' , flag = '1' 

result:

name   age   email      date    joao   23    a@a.com    20150414 joao   23    a@a.com    null 

how can group lines?? i'm looking can give me result:

name   age   email      date    joao   23    a@a.com    20150414 

thank (sorry english..)

you can use coalesce(). http://docs.oracle.com/cd/b28359_01/server.111/b28286/functions023.htm#sqlrf00617/ms190349.aspx

this query should work every name, , should coalesce other rows.

select      name1 name,     coalesce(age1, age2) age,     coalesce(email1, email2) email,     coalesce(date1, date2) date from(     select          t1.name name1,          t1.age age1,          t1.email email1,          t1.date date1,         t2.name name2,          t2.age age2,          t2.email email2,          t2.date date2      table_a t1     inner join table_a t2     on t2.flag = 1 , t1.flag = 0 , t1.name = t2.name ) t3; 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -