Re: Question about joining tables

From: Bob Badour <bbadour_at_pei.sympatico.ca>
Date: Fri, 22 Feb 2008 20:11:27 -0400
Message-ID: <47bf64b1$0$4036$9a566e8b_at_news.aliant.net>


bissatch_at_yahoo.co.uk wrote:

> Hi,
>
> Say I have two tables, one called property which stores details of
> properties, and anothe called property_image that stores a single
> image for a property. So either property may have one image or no
> image. I know how to do the following join:
>
> SELECT * FROM property, property_image WHERE property.property_id =
> property_image.property_id
>
> Works fine if I need only returned the properties that tie up with
> images but the properties that dont tie up I dont get returned in my
> result. Is it possible to create an SQL joining statement where all
> properties would be returned including the ones that dont have an
> property image? Those that dont just wouldnt have any values in the
> property_image.* columns. Traditionally I would do a query on the
> property table then for each property do a single SELECT lookup on the
> property_image table .. im sure for performance if i could reduce this
> to one query i would see an improvement.
>
> Thanks
>
> Burnsy

See UNION or LEFT OUTER JOIN. (Outer joins are just shorthands for unions but more people know outer joins than know unions for some reason.) Received on Sat Feb 23 2008 - 01:11:27 CET

Original text of this message