Article View: borland.public.interbase.sql
Article #232Re: Help with a "not in" query
From: Bill Todd [TeamB]
Date: Sun, 15 Jun 2008 22:01
Date: Sun, 15 Jun 2008 22:01
25 lines
1654 bytes
1654 bytes
Hugo wrote: > select * FROM TABLE_1 > WHERE ID_VENTA = 20081398 > AND OPCION = 1 > AND ID_ARTICULO NOT IN ( > SELECT ID_ARTICULO FROM TABLE_2 > WHERE ID_VENTA = 20081398 > AND OPCION = 1); A left outer join is usually the fastest way to perform a "not in" query. The best performance should occur if you have an index on A.ID_VENTO + A.OBCION and an index on B.ID_ARTICULO. SELECT A.* FROM TABLE_1 A LEFT OUTER JOIN TABLE_2 B ON A.ID_ARTICULO = B.ID_ARTICULO WHERE A.ID_VENTA = 20081398 AND A.OBCION = 1 AND B.ID_ARTICULO IS NULL If the query is still slow post the plan and the metadata, particularly the indices, for both tables. -- Bill Todd (TeamB)
Technical Details
Message-ID:
<4855914f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<48558e17$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,82d9b914a86c4cad,start
X-Google-Attributes: gid114a0e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Bill Todd [TeamB]" <no@no.com>
Subject: Re: Help with a "not in" query
Newsgroups: borland.public.interbase.sql
References: <48558e17$1@newsgroups.borland.com>
Organization: The Database Group, Inc.
User-Agent: XanaNews/1.18.1.9
X-Face: ":yn4zt^A_dn>6~{YJmu^B\'4w)e:apPM\VC=Dvf&*tASxX9|BYczkFd$xr.$vNSZ[3Uobr p]c4\+\l){!WQI.$]veP({HLd;CDYH?iN
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
NNTP-Posting-Host: 63.147.41.232
Message-ID: <4855914f$1@newsgroups.borland.com>
Date: 15 Jun 2008 15:01:51 -0700
X-Trace: newsgroups.borland.com 1213567311 63.147.41.232 (15 Jun 2008 15:01:51 -0700)
Lines: 25
X-Authenticated-User: btodd
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail