• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

4 queries with a date column

Participant ,
May 16, 2017 May 16, 2017

Copy link to clipboard

Copied

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?

TOPICS
Advanced techniques

Views

367

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 17, 2017 May 17, 2017

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation