I have 4 queries that have a date column. I need to output to a table sorted by date desc.
But the dates that need to be sorted are from the 4 queries.
Its not a good candidate for UNION as each query has different columns, like this
name - address -city -date
col a- col b- Date
col d col E- Date
col d -col e- col f - Date
You can still use a union:
select Col1, Col2, Col3, Col4, Col5 from ( select date as Col1, name as Col2, address as Col3, null as Col4, null as Col5 from TableA union all select date as Col1, null as Col2, null as Col3, cola as Col4, null as Col5 from TableB union all select date as Col1, null as Col2, null as Col3, null as Col4, cold as Col5 from TableC ) as DerivedTable order by Col1