Skip to content
Advertisement

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

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

Advertisement

Answer

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;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement