Highlighted

4 queries with a date column

Participant ,
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

301

Likes

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

4 queries with a date column

Participant ,
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

302

Likes

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
May 16, 2017 0
Advocate ,
May 17, 2017

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
May 17, 2017 0