-2

How to write a SQL to combine data from multiple columns and rows into one row.

OrganizationId  Name    Type    Active
--------------------------------------
      1         Baker   County  Yes
      2         curry   county  Yes

Expected result:

SomeColumnName
-------------------------------
1BakerCountyYes2currycountyYes
Sandy
  • 27
  • 1
  • 7

1 Answers1

0

MySQL

Use GROUP_CONCAT.

SELECT row_id,        
       group_concat( Value ORDER BY Value SEPARATOR ' ')
FROM 
    (SELECT 
        @row_number:=1 AS row_id,
        CONCAT(OrganizationId ,Name,Type,Active) AS Value
    FROM
        Table1
     ORDER BY file_fields_id
     ) T
GROUP BY row_id;
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115