X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B6CD5529E0 for ; Thu, 30 Jun 2005 08:18:13 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 95375-01 for ; Thu, 30 Jun 2005 11:18:05 +0000 (GMT) Received: from gauss.credativ.com (ipx11302.ipxserver.de [212.112.227.254]) by svr1.postgresql.org (Postfix) with ESMTP id B175E5280D for ; Thu, 30 Jun 2005 08:18:04 -0300 (ADT) Received: from bell.credativ.de (unknown [80.137.55.210]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by gauss.credativ.com (Postfix) with ESMTP id 6374BD7658; Thu, 30 Jun 2005 13:20:40 +0200 (CEST) From: Peter Eisentraut To: "Nick Stone" Subject: Re: SQL Query question Date: Thu, 30 Jun 2005 13:18:10 +0200 User-Agent: KMail/1.8.1 Cc: pgsql-sql@postgresql.org References: <20050630092944.E94022514BD@smtp.nildram.co.uk> In-Reply-To: <20050630092944.E94022514BD@smtp.nildram.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200506301318.11588.peter_e@gmx.net> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200506/373 X-Sequence-Number: 21974 Am Donnerstag, 30. Juni 2005 11:27 schrieb Nick Stone: > SELECT > tbl1."TermTypeID", > tbl1."ParentID", > tbl1."KeywordID", > tbl1."Term", > tbl2."KeywordID" > FROM > "Terms" As tbl1 LEFT JOIN > "SearchStore" As tbl2 ON tbl1."KeywordID" = tbl2."KeywordID" > WHERE > (tbl1."TermTypeID" >= 200) AND > (tbl1."TermTypeID" < 600) AND > (tbl1."IsSynonym" = false) AND > (tbl1."LanguageID" = 1) AND > (tbl2."StockID" = 1) > ORDER BY > tbl1."TermTypeID", > tbl1."Term"; > > Just to be obvious both queries as far as I can should return everything > from Terms and anything if it exists from SearchStore subject to the WHERE > clause parameters - obviously! The condition (tbl2."StockID" = 1) will remove all rows that have null values in the tbl2 fields, thus making your left join useless. Perhaps you should change that to (tbl2."StockID" = 1 OR tbl2."StockID" IS NULL) -- or use your first version. -- Peter Eisentraut http://developer.postgresql.org/~petere/