Reputation: 30421
I have 2 tables both containing an event
and date
column. Is there a way to combine the results of both column's event
field into one and sort them by their date
field. That way only a single (and combined) event
is returned instead of 2.
Upvotes: 0
Views: 108
Reputation: 2277
SELECT event,date FROM table1
UNION
SELECT event,date FROM table2 ORDER BY date
When using UNION you use ORDER by at bottom query it will order marged query
You can't use it except bottom query anyway it should throw an error
Upvotes: 3
Reputation: 263723
SELECT a.event, MAX(a.date) date
FROM
(
SELECT event, date FROM TableA
UNION
SELECT event, date FROM TableB
) a
GROUP BY a.event
ORDER BY a.date DESC
Upvotes: 0