Forum Moderators: open

Message Too Old, No Replies

Simple SQL question - joining tables when data may not exist

         

housecor

5:00 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



I am joining two tables to make a list of cars and their associated performance ranking doing the following (widgetized):

SELECT car.model, car_rating.performance
FROM car, car_rating
WHERE car.model_id = car_rating.model_id;

However, with this structure, cars with no rating aren't listed since this join requires an entry for the model_id in both tables. Is there any easy way around this, or do I have to put a null rating into the car_rating table for each model_id so the join pulls all models?

Thanks in advance!

LifeinAsia

5:30 pm on Apr 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



SELECT car.model, car_rating.performance
FROM car LEFT OUTER JOIN car_rating ON car.model_id = car_rating.model_id;

housecor

7:55 pm on Apr 26, 2006 (gmt 0)

10+ Year Member



Ah, I knew there had to be an easier way! Thanks!