I have this query in mysql:
SELECT MIN('Dc3') +1 as prox_ean_libre FROM (SELECT 'Dc3' FROM 'Test' WHERE 'Dc3' BETWEEN '".$Eanmin."' AND '".$Eanmax."') t1 WHERE not exists (select null FROM 'Test' t2 WHERE t2.'Dc3' = t1.'Dc3' + 1 AND t2.'Dc3' BETWEEN '".$Eanmin."' AND '".$Eanmax."'
In it I look for the first free code between two numbers. the fact is that it works but it is extremely slow when mysql has many records. Is there any way to make it faster?
Eanmin is 8434452000001 and Eanmax 8434452099999 Dc3 is a field varchar 200