473,320 Members | 2,164 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,320 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 49472
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.