trying to get a count of transfers from one account to another account within the same bank
relevant columns:
table transfers
transferid, toaccount, fromaccount
table accounts
accountid, bank
what i have now is
select count(*) from transfers where
toaccount in (select accountid from accounts where bank = @bank)and
fromaccount in(select accountid from account where where bank = @bank)
this works but is extremely slow as the accounts table is large and this has to run through it twice.
any ideas for optimizing this query
also, I don't know if this will help, but all I really care about is if there are any or not, the exact count doesn't really matter