Large Query - Concatenate Strings Horizontally

I have data with a column for first name and a column for last name. I am trying to combine them into one column using the code:

SELECT GROUP_CONCAT_UNQUOTED(full_name,' ') 
from (Select first_name as check from [DATA]), 
     (select last_name  as check from [DATA])

      

But it returns a single line string with

Anna Alex Emma Sean ... Miller Smith White ...

but I wanted actually a column like

Anna Miller
Alex Smith
Emma White
...

      

Could you tell me what I should be doing differently? Thank!

+3


source to share


1 answer


You need to use CONCAT and trim functions



SELECT CONCAT(rtrim(ltrim(first_name)),' ',rtrim(ltrim(last_name))) AS full_name
FROM
  (SELECT 'Anna' AS first_name,
          ' Miller ' AS last_name),

      

+4


source







All Articles