Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id A731C6328F3 for ; Tue, 16 Feb 2010 17:39:09 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 97956-08 for ; Tue, 16 Feb 2010 21:38:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 29D62632244 for ; Tue, 16 Feb 2010 17:38:58 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1NhV8C-0004by-Cs for pgsql-sql@postgresql.org; Tue, 16 Feb 2010 22:38:56 +0100 Received: from g224126105.adsl.alicedsl.de ([92.224.126.105]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 16 Feb 2010 22:38:56 +0100 Received: from tim by g224126105.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 16 Feb 2010 22:38:56 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: pgsql-sql@postgresql.org To: pgsql-sql@postgresql.org From: Tim Landscheidt Subject: Re: UNION or LEFT JOIN? Date: Tue, 16 Feb 2010 21:38:19 +0000 Organization: Lines: 31 Message-ID: References: <20100216140814.GA22577@apartia.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g224126105.adsl.alicedsl.de Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:42UryEJZBG8FDRQHsZrEE2KgAtU= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 201002/60 X-Sequence-Number: 33659 Louis-David Mitterrand 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. Tim