Having just had this problem myself
I have found out a couple of relavent things
It appears that that the check for NULL on a field used in the joins is a lot faster.
Also a few versions of mysql had problems testing for NULL on fields not used in the joins.
So a first improvement is to replace the o.date_purchased field with o.customers_id field
An altenative that you can try that seems to produce around the same times isCode:SELECT DISTINCT c.customers_email_address as customers_email_address, c.customers_lastname as customers_lastname, c.customers_firstname as customers_firstname FROM TABLE_CUSTOMERS c LEFT JOIN TABLE_ORDERS o ON c.customers_id=o.customers_id WHERE o.customers_id IS NULL
Both of these improved my selection times considerablyCode:SELECT DISTINCT c.customers_email_address as customers_email_address, c.customers_lastname as customers_lastname, c.customers_firstname as customers_firstname FROM TABLE_CUSTOMERS c WHERE c.customers_id NOT IN ( SELECT o.customers_id AS customers_id FROM TABLE_ORDERS o )
Obviously backup before trying either of these to see if they work for you


Reply With Quote

