Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help...left join 1

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
tblCars
CarID, MakeID, CarDescription

tblCarMakes
MakeID, Makes

tblCarImages
CarID, ImageID

tblImages
ImageID, ImageName

I want to get all details for a car, its description, make and an image for it.

SELECT *
FROM tblCars a, tblCarMakes b, tblCarImages c, tblImages d
WHERE a.CarID = <<user input>>
AND a.MakeID = b.MakeID
AND a.CarID = c.CarID
AND c.ImageID = d.ImageID

The problem here is that if a car has no image no results for that record will be shown. How do I show all results for a car even if it has no image. I know that it involves a left join but I am unsure how to do it.

Thanks,
Dessie
 
Something like this ?
SELECT *
FROM (((tblCars a
LEFT JOIN tblCarMakes b ON a.MakeID = b.MakeID)
LEFT JOIN tblCarImages c ON a.CarID = c.CarID)
LEFT JOIN tblImages d ON c.ImageID = d.ImageID)
WHERE a.CarID = <<user input>>

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That is exactly it. I didn't know how to structure my query with the left join. Thanks a lot, quick reply too.
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top