Faster MySQL Counting on JOINS
Lets say you want to count how many customers, sales and suppliers/vendors some user in your system has, in a single query. A naive approach would be to do this: SELECT user_accounts.id, user_accounts.company_name, COUNT(DISTINCT suppliers.id) AS suppliers, COUNT(DISTINCT customers.id) AS…