473,441 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

JOINING 3 Tables Using LEFT OUTER JOIN

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
3 49482
hariharanmca
1,977 1GB
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
Could someone help me with the actual SQL coding? Thanks.
Sep 7 '07 #3
azimmer
200 Expert 100+
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

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

Similar topics

3
by: Dam | last post by:
Using SqlServer : Query 1 : SELECT def.lID as IdDefinition, TDC_AUneValeur.VALEURDERETOUR as ValeurDeRetour FROM serveur.Data_tblDEFINITIONTABLEDECODES def,...
3
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
5
by: Todd | last post by:
Data related to the query I'm working on is structured such that TableA and TableB are 1-many(optional). If an item on TableA has children on TableB, I need to use the Max(tstamp) from Table B in...
3
by: rjaw | last post by:
Hi there, we have a problem using the left outer join-operation on a db2 database, v7, running on z/os. Defined are two tables, table1 and table2. Both tables have a primary key of field1,...
14
by: mike | last post by:
I'm using postgresl 7.3.2 and have a query that executes very slowly. There are 2 tables: Item and LogEvent. ItemID (an int4) is the primary key of Item, and is also a field in LogEvent. Some...
9
by: shanevanle | last post by:
I have two tables that are pretty big. I need about 10 rows in the left table and the right table is filtered to 5 rows as well. It seems when I join the tables in the FROM clause, I have to...
6
by: Avaenuha | last post by:
I need to use a left outer join to get all of one table, and match it to specific instances of another table. Eg, report all of A, and where A has made a specific kind of B, report the name of that...
3
by: pbassutti | last post by:
Hello, I'm trying to link two tables... one for Employees and the other for Timecards I need to get a list of employees that do not have timecards on an SPECIFIC DATE I tried the follonwing
1
by: nico3334 | last post by:
I have a query that currently pulls data from a main table and a second table using LEFT OUTER JOIN. I know how to do make another LEFT OUTER JOIN with the main table, but I want to add another LEFT...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.