Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select 2 columns in one and combine them

Is it possible to select 2 columns in just one and combine them?

Example:

select something + somethingElse as onlyOneColumn from someTable

like image 218
Gondim Avatar asked Mar 17 '11 14:03

Gondim


People also ask

How do I combine data from multiple columns into one in SQL?

Select the same number of columns for each query. Corresponding columns must be the same general data type. Corresponding columns must all either allow null values or not allow null values. If you want to order the columns, specify a column number because the names of the columns you are merging are probably different.

How do I combine two columns into a single column in SQL?

SELECT COALESCE(column1,'') + COALESCE(column2,'') FROM table1. For this example, if column1 is NULL , then the results of column2 will show up, instead of a simple NULL .


1 Answers

(SELECT column1 as column FROM table ) UNION  (SELECT column2 as column FROM table ) 
like image 180
surya Avatar answered Sep 22 '22 14:09

surya