Re: where clause question

From: Martin Gainty <mgainty(at)hotmail(dot)com>
To: <david(at)fetter(dot)org>, <leknarf(at)pacbell(dot)net>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: where clause question
Date: 2009-09-04 19:37:34
Message-ID: BLU142-W26D485B219B5AAB2DC5F40AEEE0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


you'll need to create an alias beforehand

SELECT foo.foo_id, foo.name
FROM foo, (SELECT * FROM foo, bar WHERE ...) bar
WHERE foo.bar_id = bar.bar_id
AND bar.name = 'martini';

Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

> Date: Fri, 4 Sep 2009 10:21:24 -0700
> From: david(at)fetter(dot)org
> To: leknarf(at)pacbell(dot)net
> CC: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] where clause question
>
> On Fri, Sep 04, 2009 at 06:47:24AM -0700, Scott Frankel wrote:
> >
> > Hello,
> >
> > Is it possible to perform selects in a where clause of a statement?
> >
> > Given a statement as follows:
> >
> > SELECT foo.foo_id, foo.name
> > FROM foo, bar
> > WHERE foo.bar_id = bar.bar_id
> > AND bar.name = 'martini';
> >
> > I'm looking for a way to recast it so that the select and from clauses
> > refer to a single table and the join referencing the second table occurs
> > in the where clause. For example, something like this:
> >
> > SELECT foo.foo_id, foo.name
> > FROM foo
> > WHERE (SELECT * FROM foo, bar WHERE ...)
> > foo.bar_id = bar.bar_id
> > AND bar.name = 'martini';
> >
> > I've explored the "where exists" clause, but it's not supported by the
> > application toolkit I'm using. AFAIK, I've only got access to where ...
>
> Sounds like a great reason to modify, or if you can't modify, replace,
> that application toolkit. This won't be the last time it will get in
> your way.
>
> Cheers,
> David.
> --
> David Fetter <david(at)fetter(dot)org> http://fetter.org/
> Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
> Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
>
> Remember to vote!
> Consider donating to Postgres: http://www.postgresql.org/about/donate
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

_________________________________________________________________
Windows Live: Keep your friends up to date with what you do online.
http://windowslive.com/Campaign/SocialNetworking?ocid=PID23285::T:WLMTAGL:ON:WL:en-US:SI_SB_online:082009

In response to

Browse pgsql-general by date

  From Date Subject
Next Message APseudoUtopia 2009-09-04 20:15:53 Full-Text Searching: to_tsquery() vs. plainto_tsquery()
Previous Message Dimitri Fontaine 2009-09-04 19:34:31 Re: strange error occurs when adding index