pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Moray McConnachie <moray.mcconnachie@computing-services.oxford.ac.uk>
To: Oskar Liljeblad <osk@hem.passagen.se>
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] query with subquery abnormally slow?
Date: Mon, 1 Nov 1999 19:59:20 -0000
Message-ID: <00a001bf24a3$96a18460$01c8a8c0@malthouse.private.net> (raw)
References: <19991101194707.A7034@oskar>

>   select *
>     from items
>     where package in
>       (select package
>          from items
>          where ...blah...
>          group by package)

Can't see why you don't rewrite this as one query:

select * from items where ... blah ... order by package;
(is it aggregates in the where clause?)

Assuming you do need to do it the way you have done it ,

SELECT * FROM items WHERE NOT EXISTS
(SELECT package FROM items itemscopy WHERE ... blah ... AND
itemscopy.itemid=items.itemid GROUP BY package);

should do it. itemid should be replaced by whatever the primary key of the
items table is. Note that in blah, fields must be referred to as
itemcopy.field1,itemcopy.field2, etc.

Yours,
Moray McConnachie




view thread (8+ messages)  latest in thread

Message-ID: <00a001bf24a3$96a18460$01c8a8c0@malthouse.private.net>
Permalink:  ../00a001bf24a3$96a18460$01c8a8c0@malthouse.private.net/
Also on:    postgresql.org/message-id/00a001bf24a3$96a18460$01c8a8c0@malthouse.private.net

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: moray.mcconnachie@computing-services.oxford.ac.uk, osk@hem.passagen.se
  Subject: Re: [SQL] query with subquery abnormally slow?
  In-Reply-To: <00a001bf24a3$96a18460$01c8a8c0@malthouse.private.net>
  References: <19991101194707.A7034@oskar> <00a001bf24a3$96a18460$01c8a8c0@malthouse.private.net>

* 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