On 24 Jan 2003, Andy wrote:
> I wrote what must be a very naive query to find such tracks. Doing an
> explain on this query gave a huge time estimate. My query is below.
> Would someone please suggest a faster approach?
>
> select t.track_id
> from track t
> where t.deleted = 'Y'
> UNION
> select track_id from track where track_id not in (
> select at.track_id from album_track at, album alb
> where at.album_id = alb.album_id and alb.deleted is null
> )
Try converting the in query into EXISTS
something like
select track_id from track where not exists (
select at.track_id from album_track at, album alb where
at.album_id=alb.album_id and alb.deleted is null and
track.track_id=at.track_id;
);