SQL multiple columns grouping in one row

grouping, sql, sql-server

Solution

You can select both with different query and join them using `UNION`

SELECT 'A' AS COL, AL1, AL2, AL3, ACB
  FROM TBL
 UNION
SELECT 'L' AS COL, LL1, LL2, LL3, LCB
  FROM TBL;

Output:

| COL | AL1 | AL2 | AL3 | ACB |
-------------------------------
|   A |   1 |   2 |   3 |   4 |
|   L |   5 |   6 |   7 |   8 |

See this SQLFiddle

Problem

I have the following table in SQL ``` AL1 | AL2 | AL3 | ACB | LL1 | LL2 | LL3 | LCB ------------------------------------------------ 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ``` I would like to convert it as ``` | L1 | L2 | L3 | CB ----------------------------- A | 1 | 2 | 3 | 4 L | 5 | 6 | 7 | 8 ``` Any help would be appreciated.

Original source