Joins or Unions

jason007

New Member
Joined
Jul 29, 2010
Messages
12
Hello All,

Question is that I use two sql queries to pull data.

one query pulls data from today going in the past, another one pull data from tommarow going foward.

Was wondering how to combine into one query as there the same columns types only differnce is one is historical the other is future.


Something like:

Select ALL

FROM
a.db.table.past
join
b. db.table.future

a. db.table.future = b.db.table.past

where
a.date_key >= ? and a.date_key<= ?
or
b.date_key >= ? and b.date_key<= ?
or
a.date_key >= ? and b.date_key<= ?

thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
hi, Jason. With optional new field to identify 'which one' is the data source.

Code:
SELECT 'Historic' AS [Which One], A.*
FROM PastTable A
WHERE put whatever criteria you need
UNION ALL
SELECT 'Future' AS [Which One], B.*
FROM FutureTable B
WHERE criteria applied to FutureTable

A good place to learn, http://www.w3schools.com/sql/default.asp

I've found SQL very easy to learn & if you're interested at all, I'd encourage you to learn it. regards, F
 
Upvote 0

Forum statistics

Threads
1,225,521
Messages
6,185,457
Members
453,292
Latest member
Michandra02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top