Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help joining tables

Status
Not open for further replies.

spiff2002

IS-IT--Management
Jan 31, 2003
40
This could be a simple query. I'm just stuck on it.

I have two tables (this is no t the best design but I'm wondering if I can't get the result that I want)

sales_table (this holds sales YTD)

brand division region cases_sold
-----------------------------------------------
brand1 south region1 200
brand1 north region3 300
brand2 north region2 400

The second table
orders_table (this holds open orders)

brand division region cases_ordered
-----------------------------------------------
brand1 south region1 200
brand1 north region3 300
brand2 north region2 400
brand3 south region1 100

when I run the query
the result should be something like

brand division region ordered+sold
-----------------------------------------------
brand1 south region1 400
brand1 north region3 600
brand2 north region2 800
brand3 south region1 100


region1 only belongs to south division
regions 2 and 3 only belong to north region

does any one have any ideas??


Thanks in advance

S.




 
Search for JOIN in BOL.


Code:
select	s.brand,
	s.division,
	s.region,
	'total' = (s.cases_sold + o.cases_ordered)
from	sales_table s
left	outer join orders_table o
on	o.brand = s.brand
and	o.division = s.division
and	o.region = s.region
 
That query doesn't bring the last line

brand3 south region1 100
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top