Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > multiple table joins


Reply
 
Thread Tools Display Modes
  #1  
Old 08-16-2003, 12:18 PM
simflex simflex is offline
Centurion
 
Join Date: Jul 2003
Posts: 131
Default multiple table joins


Hello everyone, I have the following situation:


tblAccidentEvent table relates to theEmp by empID
tblAccidentEvent table relates to tblAccidentInfo by trackingNumber
tblAccidentEvent table relates to ImagesFiles by trackingNumber
tblAccidentEvent table relates to countyDriver by accidentEventID
tblAccidentEvent table relates to tblVehicle by accidentEventID
tblAccidentEvent table relates to tblCollision by CollisionID
tblAccidentEvent table relates to tblDamage by damageID
tblAccidentEvent table relates to tblfactors by factorsID
tblAccidentEvent table relates to tblLocation by locationID
tblAccidentEvent table relates to tblweather by weatherID

The structure is like this:
tblAccidentEvent is the main table with
accidentEventID as the primary key identity not null
Empid (from theEmp table)
collisionID (from tblCollision table)
trackingNumber (from tblaccidentInfo table)
weatherID (from tblWeather table)

ImageFiles has:
ID pk not null,
trackingNumber(from tblAccidentInfo table)

tblVehicle has:
vehicleId pk identity not null
accidentEventID (from tblAccidentEvent table)
damageID (from tbldamage table)

countyDriver has:
driverID pk identity not null
accidentEventID (from tblaccidentEvent table)
driverCondition (from tblDriverCondition table)
contributingFactors (from tblfactors table)

The following are lookup tables:
tblDriverCondition,
tblLocation,
tblWeather,
tblDamage,
tblAccidentInfo,
tblFactors

I have the following query:

SELECT * FROM tblaccidentevent,
theEmp,
tblAccidentInfo,
tblDriverCondition,
Countydriver,
tblvehicle,
tblcollision,
tbldamage,
tblfactors,
tbllocation,
tblweather,
ImageFiles
where tblAccidentInfo.trackingNumber = tblaccidentEvent.trackingNumber
and tblAccidentInfo.trackingNumber = ImageFiles.trackingNumber
and tblDriverCondition.ConditionID = CountyDriver.DriverCondition
and tblAccidentEvent.accidenteventid=Countydriver.accidenteventid
and tblaccidentevent.accidenteventid = tblvehicle.accidenteventid
and tblaccidentevent.collisionid = tblcollision.collisionid
and tblvehicle.damageid = tbldamage.damageid
and tblfactors.factorsid = CountyDriver.contributingFactors
and tblaccidentevent.LocationOfImpact = tbllocation.locationid
and tblaccidentevent.weathercondition = tblweather.weatherid
and tblAccidentevent.empid = theEmp.empid
and tblAccidentevent.trackingNumber = @trackingNumber

When I run this query, some values are blank even though there are records for them on the db like
factorsDescription from tblfactors and filename from ImageFiles table.
What am I doing wrong with the query above?
Reply With Quote
  #2  
Old 08-16-2003, 12:58 PM
mikechan8888 mikechan8888 is offline
Contributor
 
Join Date: Jul 2003
Location: HK
Posts: 436
Default

You have 10 tables directly related to the main table tblAccidentEvent but in your query, you only linked it with 7 tables. Try to link these tables with tblAccidentEvent too:

ImagesFiles
factorsID
damageID

Not sure if it will solve all your problems as I am getting dizzy after long hours of work! But at least it will be a start!
Reply With Quote
  #3  
Old 08-16-2003, 04:18 PM
simflex simflex is offline
Centurion
 
Join Date: Jul 2003
Posts: 131
Default

sorry it should be more like this:

tblAccidentEvent table relates to theEmp by empID
tblAccidentEvent table relates to tblAccidentInfo by trackingNumber
tblAccidentEvent table relates to countyDriver by accidentEventID
tblAccidentEvent table relates to tblVehicle by accidentEventID
tblAccidentEvent table relates to tblCollision by CollisionID
tblAccidentEvent table relates to tblLocation by locationID
tblAccidentEvent table relates to tblweather by weatherID

CountyDriver table relates to tblDamage by damageID
CountyDriver table relates to tblfactors by factorsID

tblAccidentInfo table relates to ImagesFiles by trackingNumber
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Table Delete TheProphet Database and Reporting 1 06-16-2003 05:57 AM
Insert multiple table into one form sun919 Database and Reporting 1 05-26-2003 04:15 AM
highlight multiple rows or whole table rows.... alan_kaou Web Programming 1 04-04-2003 06:40 AM
Adding Multiple records to a table with Single event dpdsouza Database and Reporting 2 11-30-2002 04:29 AM
Multiple Table Query? Rezner Database and Reporting 0 01-08-2002 02:55 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->