Re: SQL Query question

From: "Nick Stone" <nick(at)harelane(dot)com>
To: "'Richard Huxton'" <dev(at)archonet(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: SQL Query question
Date: 2005-06-30 12:22:39
Message-ID: 20050630122442.037652526B0@smtp.nildram.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks for the reply at least that explains it.

Nick

-----Original Message-----
From: Richard Huxton [mailto:dev(at)archonet(dot)com]
Sent: 30 June 2005 12:22
To: Nick Stone
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] SQL Query question

Nick Stone wrote:
> Hi
>
> Whilst I'm not new to SQL I am reasonably new to Postgres and as such
> I have a question on the following query:

> FROM
> "Terms" As tbl1 LEFT JOIN
> "SearchStore" As tbl2 ON tbl1."KeywordID" = tbl2."KeywordID" AND
> tbl2."StockID" = 1 Why does the above query work fine and the folowing
> query not work? And as a additional kind of spanner in the works I've
> tried the following on MS SQL Server and Oracle both of which produce
> the correct results

> FROM
> "Terms" As tbl1 LEFT JOIN
> "SearchStore" As tbl2 ON tbl1."KeywordID" = tbl2."KeywordID"
> WHERE
...
> (tbl2."StockID" = 1)

Hmm - I'm not sure that MSSQL/Oracle are giving the "right" answer here.
I assume the tbl2.stockid test is the issue here, and we apply the test
after the join whereas the others push the condition inside the join.

I'm inclined to prefer PG's way of doing things, since it means you get what
you explicitly asked for (to my point of view anyway). Not sure what the SQL
spec says though, and in the end I suppose that's the only way to decide
"right".

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message M.D.G. Lange 2005-06-30 13:50:25 Updatable view
Previous Message Daryl Richter 2005-06-30 11:58:39 Re: ORDER records based on parameters in IN clause