Re: SQL Query question - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: SQL Query question
Date
Msg-id 200506301318.11588.peter_e@gmx.net
Whole thread Raw
In response to SQL Query question  ("Nick Stone" <nick@harelane.com>)
List pgsql-sql
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/


pgsql-sql by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: ENUM like data type
Next
From: Richard Huxton
Date:
Subject: Re: SQL Query question