SQL Joins question

I have three tables which all have the following data:-

table 1
warehouse
product
purchases_thismonth
purchases_nextmonth
purchases_monthafter

table2
warehouse
product
orders_thismonth
orders_nextmonth
orders_monthafter

table3
warehouse
product
quotes_thismonth
quotes_nextmonth
quotes_monthafter

I want to create a query which basically pulls my data together into the following format

warehouse,product,purchases_thismonth,purchases_nextmonth,purchases_monthafter,orders_thismonth,orders_nextmonth,orders_monthafter,quotes_thismonth,quotes_nextmonth,quotes_monthafter

I have tried to do this but I keep getting multiple lines for each product.
Any ideas what I am doing wrong or indeed what I should be doing
sagarhAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

riaancorneliusCommented:
>
Use inner joins.
riaancorneliusCommented:
example:
SELECT table1.warehouse, table1.product, table2.orders_thismonth
FROM table1 INNER JOIN table 2
ON table1.product = table2.product
Renante EnteraSenior PHP DeveloperCommented:
Hi sagarh!

I think this is what you are looking for :

Select
  t1.warehouse, t1.product, t1.purchases_thismonth, t1.purchases_nextmonth, t1.purchases_monthafter,
  t2.orders_thismonth, t2.orders_nextmonth, t2.orders_monthafter,
  t3.quotes_thismonth, t3.quotes_nextmonth, t3.quotes_monthafter
From  Table1 t1
Left Join Table2 t2
  On t2.warehouse = t1.warehouse And t2.product = t1.product
Left Join Table3 t3
  On t3.warehouse = t1.warehouse And t3.product = t1.product

Hope this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Renante EnteraSenior PHP DeveloperCommented:
Hi sagarh!

I'm glad that I have helped you.  Hope to help you again.


Regards!
eNTRANCE2002 :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.