[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL Joins question

Posted on 2005-05-06
4
Medium Priority
?
202 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:sagarh
  • 2
  • 2
4 Comments
 
LVL 9

Expert Comment

by:riaancornelius
ID: 13943595
>
Use inner joins.
0
 
LVL 9

Expert Comment

by:riaancornelius
ID: 13943600
example:
SELECT table1.warehouse, table1.product, table2.orders_thismonth
FROM table1 INNER JOIN table 2
ON table1.product = table2.product
0
 
LVL 14

Accepted Solution

by:
Renante Entera earned 2000 total points
ID: 13943642
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 :-)
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 13949243
Hi sagarh!

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


Regards!
eNTRANCE2002 :-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question