i have 2 tables of about 3000/4000 rows. I need to make a relation using Left Join for filter the results by searching a text or datetime. I need also to count a total row for pagination. When i run the query is epic slow, consider about 40/45 seconds by console and more than a minute from webpage. The relation is: for 1 of tableA have N in tableB. There is a solution for have a fast query? The sample query is:
SELECT X,Y,Z, (SELECT COUNT(*)
FROM tableB WHERE tableB.idTa=tableA.id) AS CountTB
FROM tableA
LEFT JOIN tableB ON tableA.id = tableB.idA
WHERE tableA.X LIKE'%mytext%' OR tableB.Z LIKE'%mytext%'
GROUP BY tableA.id
ORDER BY tableA.Y LIMIT 0,10
Thank you all
ON clause is present of course. only mistyped from my phone. Now it's correct and very slow :)
New update: If I change the relationship from LEFT JOIN to RIGHT JOIN it become pretty fast....why??