List:General Discussion« Previous MessageNext Message »
From:Baron Schwartz Date:October 25 2007 10:26am
Subject:Re: correct way to simulate 'except' query in mysql 4.1
View as plain text  
Hi,

Russell Uman wrote:
> 
> howdy.
> 
> i trying to find items in one table that don't exist in another.
> i'm using a left join with a where clause to do it:
> 
> SELECT t1.field, t2.field FROM table1 t1 LEFT JOIN table2 t2 ON t1.word 
> = t2.word WHERE t2.word IS NULL;
> 
> both tables are quite large and the query is quite slow.
> 
> the field column is indexed in both tables, and explain shows the 
> indexes being used.
> 
> is there a better way to construct this kind of query?

That is the right way, but if you show us the exact output of EXPLAIN we 
can help more.  In particular, does it say "Using distinct/not exists" 
in Extra?

Baron
Thread
correct way to simulate 'except' query in mysql 4.1Russell Uman25 Oct
  • Re: correct way to simulate 'except' query in mysql 4.1Baron Schwartz25 Oct
Re: correct way to simulate 'except' query in mysql 4.1Russell Uman25 Oct
  • Re: correct way to simulate 'except' query in mysql 4.1Baron Schwartz26 Oct
    • Re: correct way to simulate 'except' query in mysql 4.1Russell Uman28 Oct
      • Re: correct way to simulate 'except' query in mysql 4.1Baron Schwartz28 Oct
        • Re: correct way to simulate 'except' query in mysql 4.1Russell Uman28 Oct