Home > Net >  Concatenate the contents of two rows into one column (SQL DB2)
Concatenate the contents of two rows into one column (SQL DB2)

Time:05-07

as it says in the title, I need to return two records but in the same column, for example (I clarify that the following code does not work, it is only to understand my case):

SELECT (NAMESS   "|"   LASTNAMESS), AGE
FROM PERSON

When doing the query, it would have to return something like Johnny|Depp in the first column and 45 in the second

CodePudding user response:

There are 2 methods to concat the fields in DB2.

  1. CONCAT function -
SELECT CONCAT(NAMESS, LASTNAMESS), AGE
FROM PERSON;
  1. Concat Operator i.e. '||' -
SELECT NAMESS || LASTNAMESS, AGE
FROM PERSON;
  • Related