My table
+-----------+---------+
| Date | Letter |
+-----------+---------+
| 13.02.2013| B |
| 01.03.2016| A |
| 28.12.2003| C |
| 12.01.2017| B |
| 25.04.2011| A |
+-----------+---------+
I created a query which returns right data, but not as expected:
SELECT * from
(
SELECT TOP 1 Date as Date1, Letter as Letter1 from TAB where
Letter = 'A'
order by Date DESC
) TAB
UNION
SELECT * from
(
SELECT TOP 1 Date as Date2, Letter as Letter2 from TAB where
Letter = 'B'
order by Datum DESC
) TAB
Expected output:
+-----------+---------+-----------+---------+
| Date1 | Letter1 | Date2 | Letter2 |
+-----------+---------+-----------+---------+
| 01.03.2016| A | 12.01.2017| B |
+-----------+---------+-----------+---------+
Output:
+-----------+---------+
| Date1 | Letter1 |
+-----------+---------+
| 01.03.2016| A |
| 12.01.2017| B |
+-----------+---------+
Is it possible get all 4 rows like expected using UNION?
Thank you.