From: Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>
To: pgsql-sql@postgresql.org
Subject: Re: UNION or LEFT JOIN?
Date: Tue, 16 Feb 2010 22:43:05 +0100
Message-ID: <20100216214305.GA22807@apartia.fr> (raw)
In-Reply-To: <m3635wuaic.fsf@passepartout.tim-landscheidt.de>
References: <20100216140814.GA22577@apartia.fr>
<m3635wuaic.fsf@passepartout.tim-landscheidt.de>
On Tue, Feb 16, 2010 at 09:38:19PM +0000, Tim Landscheidt wrote:
> Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org> wrote:
>
> > Here is the basic schema:
>
> > -------------------------->id_ship>-----------------------
> > | |
> > [SHIP]->id_ship->[CABIN]->id_cabin->[PRICE]<-id_cruise<-[CRUISE]
>
> > It's a database of cruise prices.
>
> > Each 'price' object has a reference to 'cabin' and 'cruise'
>
> > 'cabin' belongs to a 'ship', so does 'cruise'
>
> > I'm trying to select all cabins of cruise N°1 with prices OR nothing if
> > there is no price (meaning cabin not available). I want all cabins
> > listed, price or no price.
>
> > Also when doing the query I don't have the id_ship, only the id_cruise.
>
> > What is the best way of doing it? UNION or LEFT JOIN? I tried the latter
> > without success and am unsure on how do do the former.
>
> Was does "without success" mean? The objective seems to be
> straight-forward:
>
> - Select all cabins that belong to the ship that belongs to
> the cruise id_cruise.
> - Left join that with the prices of the cruise id_cruise.
Definitely the way to go. As the real schema is quite a bit more
complicated I was struggling with very long statements, but finally
succeded with a simple left join.
Thanks,
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: vindex+lists-pgsql-sql@apartia.org
Subject: Re: UNION or LEFT JOIN?
In-Reply-To: <20100216214305.GA22807@apartia.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox