So I have 3 tables, db, db2, db3. I need all the rows from db, but also the total number in db2 and db3. I would like to do it in one query and the query below works..
SELECT *, (SELECT COUNT(*) FROM db2) AS total2, (SELECT COUNT(*) FROM db3) AS total3
FROM db
What I am wondering is, since those nested SQL queries show up in every row, do they run that many time? or does mysql optimize such that it runs it once, makes it a constant, and adds it to every row?? Its important to know in case the db gets to be pretty big;
Answers and references to documentation on this would be much appreciated.