I have a SQL query which looks like the following.
SELECT A.a, count(B.id)
FROM TableA A inner join TableA B on A.referId = B.id
WHERE A.id in (123,2424,232...)
GROUP BY A.id
While executing this query
- The rows are filtered using where clause first and then join is performed or
- First join is performed, then the rows are filtered?
I am running this query on MySQL Server. Assuming TableA contains million rows. Is there any alternative and efficient way of writing this query?