Received: from oxmail.ox.ac.uk (oxmail1.ox.ac.uk [129.67.1.1]) by hub.org (8.9.3/8.9.3) with ESMTP id PAA91369 for ; Mon, 1 Nov 1999 15:01:50 -0500 (EST) (envelope-from moray.mcconnachie@computing-services.oxford.ac.uk) Received: from heraldgate1.oucs.ox.ac.uk ([163.1.2.49] helo=frontend1.herald.ox.ac.uk ident=exim) by oxmail.ox.ac.uk with esmtp (Exim 2.10 #1) id 11iNeF-0005Z1-00; Mon, 1 Nov 1999 20:01:47 +0000 Received: from max174.public.ox.ac.uk ([192.76.27.174] helo=mainbox.malthouse.private.net) by frontend1.herald.ox.ac.uk with smtp (Exim 2.02 #1) id 11iNeF-0000V4-00; Mon, 1 Nov 1999 20:01:47 +0000 Message-ID: <00a001bf24a3$96a18460$01c8a8c0@malthouse.private.net> From: "Moray McConnachie" To: "Oskar Liljeblad" , References: <19991101194707.A7034@oskar> Subject: Re: [SQL] query with subquery abnormally slow? Date: Mon, 1 Nov 1999 19:59:20 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 > 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