nathen
nathen

Reputation: 23

Combine data from multiple columns into a single column using Microsoft Access SQL

I have a data set in Access which looks like in the below image

           col1  col2 col3
    row1   12     23
    row2   34     45   56
    row3   22     33   44
    row4   99
    

But I want it to be like this

       row1  12
       row2  23 
       row3  34
       row4  45
       row5  56
       row6  22
       row7  33
       row8  44
       row9  99
   

Is there any way to do this? Your help is highly appreciated as I am new to ms access.

Upvotes: 2

Views: 12339

Answers (1)

Alexander Bell
Alexander Bell

Reputation: 7918

You can achieve it by using the UNION SQL query as in the following example:

SELECT field_1[, field_2,…]
FROM table_1[, table_2,…]
UNION [ALL]
SELECT field_a[, field_b,...]
FROM table_a[, table_b,…];

Pertinent to your case, it should look like the following:

SELECT col1
FROM table_1
UNION
SELECT col2
FROM table_1
UNION
SELECT col3
FROM table_1;

More reading here: https://support.office.com/en-us/article/Combine-the-results-of-several-select-queries-by-using-a-union-query-3856f16c-0a22-43f2-8c23-29ec44acbc05?ui=en-US&rs=en-US&ad=US Best regards,

Upvotes: 4

Related Questions