Skip to main content
Inspiring
May 16, 2017
Question

4 queries with a date column

  • May 16, 2017
  • 1 reply
  • 447 views

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

Query 1

name - address -city -date

Query 2

col a- col b- Date

Query 3

col d col E- Date

Query 4

col d -col e- col f   - Date

Anysuggestionss?

This topic has been closed for replies.

1 reply

EddieLotter
Inspiring
May 17, 2017

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

Cheers

Eddie