You need to do the aggregates within Dervied Tables and then Outer join them:
SELECT
acct.acc_no,
acct.sort_code,
COALESCE(credit.cnt, 0) AS credit_count,
COALESCE(debit.cnt, 0) AS debit_count
FROM account_details acct
LEFT JOIN
(
SELECT acc_no, sort_code, COUNT(*) AS cnt
FROM credit_trans
) AS credit
ON acct.acc_no = credit.acc_no
AND acct.sort_code = credit.sort_code
LEFT JOIN
(
SELECT acc_no, sort_code, COUNT(*) AS cnt
FROM debit_trans
) AS debit
on acct.acc_no = debit.acc_no
AND acct.sort_code = debit.sort_code
Dieter
You need to do the aggregates within Dervied Tables and then Outer join them:
Dieter