473,473 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Issues with LEFT join on four tables

Hi Folks,
Lets assume I have three tables. Their layout is as follows. Please
note that tblPeople does not have an entry for Denver (this is my
problem)

tblCity
_________________
CityName OCID
LA 1
Denver 2

tblCars
_________________
OCID CarVolume
1 300,000
2 200,000

tblPeople
_________________
OCID PeopleVolume
1 1,200,345

tblDogs
_________________
OCID DogVolume
1 234,987
2 445,987

I'd like to run a quiery that returns the following data set:

CityName OCID CarVolume PeopleVolume DogVolume
LA 1 300000 1200345 234987
Denver 2 200000 null or 0 445997

My problem is the people table. Since there not entry for Denver, my
query is returning only a row for LA, nothing for Denver. Here's wht
my query looks like

Select tblCity.CityName, tblCity.OCID, tblCars.CarVolume,
tblPeople.PeopleVolume, tblDogs.DogVolume
FROM tblCity
LEFT JOIN tblCars on tblCity.OCID = tblCars.OCID
JOIN tblPeople on tblCars.OCID = tblPeople.OCID
JOIN tblDogs on tblPeople.OCID = tblDogs.OCID

This returns the following:
CityName OCID CarVolume PeopleVolume DogVolume
LA 1 300000 1200345 234987

I need this query to return a row for Denver as well. Any thoughts
anyone?
Your insight is greatly appreciated. ericlangland at hotmail.com
Jul 20 '05 #1
1 5604
Eric,

If tblCity is your base (or primary) table, then you should be able to do
the following without problems. It appears you are very close to this
already.

select ci.ocid, ci.cityname, ca.carvolumn, p.peoplevolumn, d.dogvolumn
from tblcity ci
left join tblcars ca on ci.ocid = ca.ocid
left join tblpeople p on ci.ocid = p.ocid
left join tbldogs d on ci.ocid = d.ocid

HTH,

Greg
"Eric" <er**********@hotmail.com> wrote in message
news:53*************************@posting.google.co m...
Hi Folks,
Lets assume I have three tables. Their layout is as follows. Please
note that tblPeople does not have an entry for Denver (this is my
problem)

tblCity
_________________
CityName OCID
LA 1
Denver 2

tblCars
_________________
OCID CarVolume
1 300,000
2 200,000

tblPeople
_________________
OCID PeopleVolume
1 1,200,345

tblDogs
_________________
OCID DogVolume
1 234,987
2 445,987

I'd like to run a quiery that returns the following data set:

CityName OCID CarVolume PeopleVolume DogVolume
LA 1 300000 1200345 234987
Denver 2 200000 null or 0 445997

My problem is the people table. Since there not entry for Denver, my
query is returning only a row for LA, nothing for Denver. Here's wht
my query looks like

Select tblCity.CityName, tblCity.OCID, tblCars.CarVolume,
tblPeople.PeopleVolume, tblDogs.DogVolume
FROM tblCity
LEFT JOIN tblCars on tblCity.OCID = tblCars.OCID
JOIN tblPeople on tblCars.OCID = tblPeople.OCID
JOIN tblDogs on tblPeople.OCID = tblDogs.OCID

This returns the following:
CityName OCID CarVolume PeopleVolume DogVolume
LA 1 300000 1200345 234987

I need this query to return a row for Denver as well. Any thoughts
anyone?
Your insight is greatly appreciated. ericlangland at hotmail.com

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: StealthBananaT | last post by:
My database has two tables - films has 10,000 records and reviews has 20,000 records. Whenever I try to list all the films and the count of its reviews, MySQL locks and I have to restart the...
0
by: Petre Agenbag | last post by:
Hi List Me again. I'm trying to return from multiple tables, the records that have field "information_sent" between two dates. The tables are all related by means of the id of the entry in the...
0
by: Soefara | last post by:
Dear Sirs, I am experiencing strange results when trying to optimize a LEFT JOIN on 3 tables using MySQL. Given 3 tables A, B, C such as the following: create table A ( uniqueId int not...
1
by: Paul Bramscher | last post by:
Here's one for pathological SQL programmers. I've got a table of things called elements. They're components, sort of like amino acids, which come together to form complex web pages -- as nodes...
4
by: Marek Kotowski | last post by:
Hi, What is the real difference between LEFT JOIN and RIGHT JOIN? Are there situations where a query with RIGHT JOIN cannot be rewritten with LEFT JOIN and tables reversed? (and vice versa). ...
0
by: tricard | last post by:
Good day all, I have four tables that I am attempting to LEFT JOIN together in a query: tblPartNumber (PartNumberID is primary key autonumber) tblPartNumberVendor (PartNumberVendorID is primary...
1
by: Eitan M | last post by:
Hello, I want to do select like this : select t1.col_2 from table_1 t1, table_2 t2 where t1.col_1 = t2.col_1 (+) The above is correct syntax for Oracle. What is the correct syntax for...
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...
17
by: bobo420 | last post by:
Hi! I have 4 tables (table1, table2, table3, table 4) I need to do select * from all four table and get them sorted all the tables have field named id, so I figured that's the field I should...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.