Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB2: Function to merge 3 column output

Tags:

sql

db2

I have below records in table1

c1  c2  c3
----------
A   B   C

How to merge c1 c2 and c3 so the output would like

A B C with space in between the output I used concat function but its not taking 3 arguments like

select concat (c1,c2,c3) from table1

I cant run select * from table1 as I want output in one column

like image 781
Deepak Avatar asked Mar 06 '13 15:03

Deepak


People also ask

How do I concatenate 3 columns in SQL?

To concatenate more than 2 fields with SQL, you can use CONCAT() or CONCAT_WS() function.

How do I MERGE columns in DB2?

In SQL SELECT statements, you can concatenate columns by using a special operator “||” or using CONCAT function.

How do I concatenate two fields in DB2?

You can concatenate strings by using the CONCAT operator or the CONCAT built-in function. When the operands of two strings are concatenated, the result of the expression is a string. The operands of concatenation must be compatible strings.

Which is faster MERGE or insert?

MERGE has more flexible OUTPUT . OUTPUT can refer to the merge source which is handy if you want the client to be able to match what it sent to what was actually inserted (e.g. IDENTITY values).


2 Answers

This works in z/OS versions at least:

select c1 concat ' ' concat c2 concat ' ' concat c3

Get to know the DB2 documentation

like image 180
GilShalit Avatar answered Nov 06 '22 09:11

GilShalit


try this.

select concat(concat (c1,c2),c3) from table1
like image 33
Mortalus Avatar answered Nov 06 '22 09:11

Mortalus