Re: LEFT JOIN ...

From: The Hermit Hacker <scrappy(at)hub(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <pgsql-sql(at)postgresql(dot)org>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: LEFT JOIN ...
Date: 2001-06-18 18:26:41
Message-ID: Pine.BSF.4.33.0106181525140.22744-100000@mobile.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

On Mon, 18 Jun 2001, Tom Lane wrote:

> The Hermit Hacker <scrappy(at)hub(dot)org> writes:
> > FROM note_links nl, notes n LEFT JOIN calendar c ON (n.nid = c.nid)
> > WHERE (n.type = 'A' OR n.type = 'N' OR n.type = 'H' OR n.type = 'C')
> > AND (nl.id = 15748 AND contact_lvl = 'company')
> > AND n.nid = nl.nid
> > ORDER BY start DESC;
>
> > Is there some way to write the above so that it evaluates:
> > first, so that it only has to do the LEFT JOIN on the *one* n.nid that is
> > returned, instead of the 86736 that are in the table?
>
> Try adding ... AND n.nid = 15748 ... to the WHERE. It's not very
> bright about making that sort of transitive-equality deduction for
> itself...

n.nid is the note id ... nl.id is the contact id ...

I'm trying to pull out all notes for the company with an id of 15748:

sepick=# select * from note_links where id = 15748;
nid | id | contact_lvl | owner
-------+-------+-------------+-------
84691 | 15748 | company | f
(1 row)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-06-18 18:33:21 Re: AW: Re: [SQL] behavior of ' = NULL' vs. MySQL vs. Stand ards
Previous Message Alex Pilosov 2001-06-18 18:23:08 Re: (Really) Re: [PATCH] inet << indexability

Browse pgsql-sql by date

  From Date Subject
Next Message Alla 2001-06-18 18:34:00 Passing cursor between functions in embedded SQL
Previous Message Stephan Szabo 2001-06-18 18:18:49 Re: LEFT JOIN ...