I'm having some major issues with an SQL statement, the following statement causes so much stress to the MySQL engine it pretty much hangs:
select c.title, c.initial, c.surname, c.labelno, c.email, br1.bookingdate
from explorer.booking_record br1
inner join explorer.client c
on c.labelno = br1.labelno
and email not like ''
where br1.bookingdate >= '2009-01-01'
and br1.bookingdate < '2009-01-31'
and c.labelno Not In (Select labelno from explorer.booking_record br2 where br2.labelno = br1.labelno and br2.bookingdate >= '2010-01-01' and br2.bookingdate < '2010-01-31')
I've tried a few variations on the same, without the joins and two sub-statements, adding 'order by' as advised by the documentation. There aren't actually that many records in the database, booking_record has ~500,000 records and client has ~450,000. If I let the query run it's usually got about 20 results after 70-80 seconds, but this causes the service to go into a loop-like state.
Any advice would be much appreciated.
Daniel.