By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,267 Members | 1,808 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,267 IT Pros & Developers. It's quick & easy.

JOINING 3 Tables Using LEFT OUTER JOIN

P: 28
I currently have a query that Joins 2 Tables (Table1 and Table2) using
LEFT OUTER JOIN. Here is an example of that query:

SELECT a.supply,
a.state,
b.cost
FROM Table1 a
LEFT OUTER JOIN Table2 b
ON a.supply = b.supply
AND a.state = b.state
GROUP BY a.supply, a.state, b.cost

I would like to add additional data to this query by adding a 3rd Table. I made
this separate query which Joins Table1 and Table3:

SELECT a.supply,
FROM Table1 a
LEFT OUTER JOIN Table3 c
ON a.supply = c.supply
GROUP BY a.supply, c.number, c.number2

My problem is that I don't want to join Tables 2 and 3 because Table3 does not
have one of the columns that Table1 and 2 use to JOIN. So, I just want to JOIN
Tables 1 & 3 and keep my 1st query which joins Tables 1 & 2. Is there a way to
add my 2nd query to my 1st query without messing up the JOIN? If anyone could
give me some coding examples, I'd greatly appreciate it. Thanks!
Sep 7 '07 #1
Share this Question
Share on Google+
3 Replies


hariharanmca
100+
P: 1,977
You can Join Table2 and Table3 toe Table1.
So table 1 have both Table 2,3 key to join then no need to join Table1 to 2 as view1 and table 1 to3 as View2.
Sep 7 '07 #2

P: 28
Could someone help me with the actual SQL coding? Thanks.
Sep 7 '07 #3

azimmer
Expert 100+
P: 200
I currently have a query that Joins 2 Tables (Table1 and Table2) using
LEFT OUTER JOIN. Here is an example of that query:

SELECT a.supply,
a.state,
b.cost
FROM Table1 a
LEFT OUTER JOIN Table2 b
ON a.supply = b.supply
AND a.state = b.state
GROUP BY a.supply, a.state, b.cost

I would like to add additional data to this query by adding a 3rd Table. I made
this separate query which Joins Table1 and Table3:

SELECT a.supply,
FROM Table1 a
LEFT OUTER JOIN Table3 c
ON a.supply = c.supply
GROUP BY a.supply, c.number, c.number2

My problem is that I don't want to join Tables 2 and 3 because Table3 does not
have one of the columns that Table1 and 2 use to JOIN. So, I just want to JOIN
Tables 1 & 3 and keep my 1st query which joins Tables 1 & 2. Is there a way to
add my 2nd query to my 1st query without messing up the JOIN? If anyone could
give me some coding examples, I'd greatly appreciate it. Thanks!
Expand|Select|Wrap|Line Numbers
  1. SELECT a.supply, 
  2.        a.state, 
  3.        b.cost
  4. FROM (Table1 a LEFT OUTER JOIN Table2 b ON a.supply = b.supply AND a.state = b.state) LEFT OUTER JOIN Table3 c ON a.supply = c.supply
  5. GROUP BY a.supply, a.state, b.cost, c.number, c.number2
  6.  
Sep 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.