Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to combine two columns into one column having either one of the column

Tags:

sql

I have two column in the table

column 1     column 2
........     .........
v1           v4
v2           v5
NULL         v6
NULL         v7 
NULL         v8

where v1 v2 v3 v4 v5 v6 are the values of the column type is varchar I want to get the output as merged columns but should have only value of the first column

column 1
.......
v1 
v2 
v6 
v7 
v8
like image 215
Anup Avatar asked Dec 10 '25 03:12

Anup


1 Answers

Standard SQL is COALESCE:

SELECT COALESCE(column1,column2) as column1
FROM ...
like image 87
Damien_The_Unbeliever Avatar answered Dec 11 '25 21:12

Damien_The_Unbeliever