It appears my SQL isn't limiting results based on price
.
In my previous post, http://stackoverflow.com/questions/1039771/sql-help-me-optimize-my-sql, people indicated that I should use a LEFT OUTER JOIN.
SELECT homes.home_id,
address,
city,
state,
zip,
price,
photo_id,
photo_url_dir
FROM homes
LEFT OUTER JOIN home_photos ON homes.home_id = home_photos.home_id
AND primary_photo_group_id = home_photo_group_id
AND home_photo_type_id =2
AND display_status = true
AND homes.price BETWEEN 500000 AND 1000000
However, it's still displaying homes whose price is < 500000
I don't understand. Why would the SQL above display homes that have a price less than 500000 when I have a WHERE condition to limit exactly that field.
Thanks for your help.
What I want to do
I want to display both homes with and homes without a home_photo based on criteria like PRICE
between X and Y ... or SQFT
> Z. But these criteria needs to be applied to both those homes with and those homes
without a home_photo
Is this correct?
SELECT homes.home_id,
address,
city,
state,
zip,
price,
photo_id,
photo_url_dir
FROM homes
LEFT OUTER JOIN home_photos ON homes.home_id = home_photos.home_id
AND homes.primary_photo_group_id = home_photos.home_photo_group_id
AND home_photos.home_photo_type_id =2
WHERE homes.display_status = true
AND homes.price BETWEEN 500000 AND 1000000