0

I have a table with 4 rows with DateTime values saved into.

The query:

SELECT row1, row2, row3, row4 FROM table;

shows this result:

+------------+------------+------------+------------+
|    row1    |    row2    |    row3    |    row4    |
+------------+------------+------------+------------+
|01.01.2014  |null        |null        |31.12.2018  |
|null        |17.08.2015  |01.12.2050  |null        |
|02.01.2010  |null        |28.03.2067  |null        |
+------------+------------+------------+------------+

But I want to combine and order these dates into one row like:

+------------+
|    rows    |
+------------+
|01.01.2014  |
|02.01.2010  |
|17.08.2015  |
|01.12.2050  |
|28.03.2067  |
|31.12.2018  |
+------------+

What query do I have to use to get the result I want?

Thanks in advance

1 Answer 1

2
SELECT row1 AS rows FROM table WHERE row1 IS NOT NULL
UNION ALL
SELECT row2 AS rows FROM table WHERE row2 IS NOT NULL
UNION ALL
SELECT row3 AS rows FROM table WHERE row3 IS NOT NULL
UNION ALL
SELECT row4 AS rows FROM table WHERE row4 IS NOT NULL
ORDER BY rows DESC;

will do what you want I guess.

Do you have more info about the problem, eg table and column names.

Sign up to request clarification or add additional context in comments.

1 Comment

You should add order by row1 to order the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.