From: Tony Wasson <ajwasson@gmail.com>
To: Ragnar Hafstaư <gnari@simnet.is>
Cc: pgsql-sql@postgresql.org
Subject: Re: left joins
Date: Wed, 6 Jul 2005 18:11:32 -0700
Message-ID: <6d8daee305070618117ab12541@mail.gmail.com> (raw)
In-Reply-To: <1120695557.14290.22.camel@localhost.localdomain>
References: <20050706103303.3C2C424E7A4@smtp.nildram.co.uk>
<1120695557.14290.22.camel@localhost.localdomain>
On 7/6/05, Ragnar Hafstaư <gnari@simnet.is> wrote:
> On Wed, 2005-07-06 at 11:33 +0100, Nick Stone wrote:
> > I've had exactly yhe same problem - try changing the query to.
> >
> > select count(*)
> > from h left join p using (r,pos) and p.r_order=1
> > where h.tn > 20
> > and h.tn < 30
>
> really ? is this legal SQL ?
> is this a 8.0 feature ?
> I get syntax error at or near "and" at character 41
>
SQL like this works for me when I write it with an ON statement
instead of a USING.
select count(*)
from h left join p on (h.r=p.r and h.pos=r.pos and p.r_order=1)
where h.tn > 20
and h.tn < 30
Filtering within the join condition is very useful when doing a left outer join.
Here's another example "from the book" doing this type of filter
within the join:
http://www.postgresql.org/docs/8.0/interactive/queries-table-expressions.html
Tony Wasson
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: ajwasson@gmail.com, gnari@simnet.is
Subject: Re: left joins
In-Reply-To: <6d8daee305070618117ab12541@mail.gmail.com>
* 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