2
I have a table called "readings" where my search returns 10 thousand results for the equipmentid = 1
SELECT id, result, date FROM readings WHERE equipamentid = 1;
for each returned result I need to bring another data with equal smaller date nearest now referring to the equipmentid = 2
SELECT result FROM readings WHERE equipamentid = 2 AND date <= date(data da primeira busca) ORDER BY date DESC LIMIT 1
The code works perfectly, but as the first search returns 10 thousand results, another 10 thousand searches of the next equipment, which makes everything very slow. I have tried also to perform using LEFT JOIN but the runtime is the same, it is unviable.
Is there another way I haven’t been able to visualize yet to solve this problem, and gain performance?
already created index to optimize the query? link
– Adriano Campos