1 Reply Latest reply on May 17, 2017 12:09 PM by EddieLotter

    4 queries with a date column

    weezerboy Level 1

      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?

        • 1. Re: 4 queries with a date column
          EddieLotter Level 4

          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