For example:
SELECT account.IDENTIFIER, subscriptionCount.subscriptions, promotionCount.promotions
FROM tomtomtbaccount account
JOIN (SELECT account_fk, COUNT(*) AS subscriptions FROM tomtomtbsubscription GROUP BY account_fk) subscriptionCount ON account.account_id = subscriptionCount.account_fk
JOIN (SELECT account_fk, COUNT(*) AS promotions FROM tomtomtbpromotion GROUP BY account_fk) promotionCount ON account.account_id = promotionCount.account_fk
ORDER BY subscriptionCount.subscriptions
LIMIT 100;
(this query is a bit heavy though...)
Also a nice memonic Wouter provided:
if you want results side by side: JOIN
if you want results in a list: UNION
No comments:
Post a Comment