pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nick Stone <nick@harelane.com>
To: 'Richard Huxton' <dev@archonet.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL Query question
Date: Thu, 30 Jun 2005 13:22:39 +0100
Message-ID: <20050630122442.037652526B0@smtp.nildram.co.uk> (raw)
In-Reply-To: <42C3D5E9.8010007@archonet.com>

Thanks for the reply at least that explains it.

Nick 

-----Original Message-----
From: Richard Huxton [mailto:dev@archonet.com] 
Sent: 30 June 2005 12:22
To: Nick Stone
Cc: pgsql-sql@postgresql.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






view thread (8+ messages)  latest in thread

Message-ID: <20050630122442.037652526B0@smtp.nildram.co.uk>
Permalink:  ../20050630122442.037652526B0@smtp.nildram.co.uk/
Also on:    postgresql.org/message-id/20050630122442.037652526B0@smtp.nildram.co.uk

 · 

reply

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: nick@harelane.com, dev@archonet.com
  Subject: Re: SQL Query question
  In-Reply-To: <20050630122442.037652526B0@smtp.nildram.co.uk>

* 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