sql - when one column null then get data from other column -


hope can help. not showing whole query because don't think required want try , query see there null value in 'street' in 'free address' , put result in there. i'm guessing involves case expression or concat

current result

select  idnum street free address  id   idnum          street                  free address   1          stack on flow               null   2             null                   stack exchange   3           downing street               null 

required result - note free address column doesn't need on display, purpose of demonstration.

 idnum          street                    free address    1         stack on flow                  null    2         stack exchange                stack exchange    3         downing street                   null 

many help

the coalesce() function this:

select idnum,        coalesce(street, free_address) street,        free_address id; 

note: id strange name table , free address isn't valid column name (because of space).

coalesce() ansi standard function available in databases.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -