chinthakarukshan
chinthakarukshan

Reputation: 141

Split One Row in to Two Rows in SQL

I have a table with below columns

PAX_NO | AMOUNT_ONE | AMOUNT_TWO | PAX_NO_LASTYEAR | AMOUNT_ONE_LASTYEAR | AMOUNT_TWO_LASTYEAR
45     |  56.54     |  43.23     |   23            |      23.43          |       78.43
69     |  21.11     |  51.19     |   20            |      11.23          |       55.99

I need to get it as below

PAX_NO  |  AMOUNT_ONE    | AMOUNT_TWO
45      |      56.54     |    43.23
23      |      23.43     |    78.43
69      |      21.11     |    51.19
20      |      11.23     |    55.99

Upvotes: 0

Views: 951

Answers (1)

Przemyslaw Kruglej
Przemyslaw Kruglej

Reputation: 8123

You can just use UNION ALL:

SELECT pax_no, amount_one, amount_two FROM your_table
UNION ALL
SELECT PAX_NO_LASTYEAR, AMOUNT_ONE_LASTYEAR, AMOUNT_TWO_LASTYEAR FROM your_table;

Upvotes: 4

Related Questions