mysql - adding vlues in a table and displaying highest vsalue -


i have 2 tables

 account  account_number     balance  -------------      --------   depositor  account_number     name  --------------     ---- 

what need display name , value of highest account. used following statement names , account values in 1 place.

select account.balance, depositor.customer_name 2  account 3  inner join depositor 4  on account.account_number = depositor.account_number;  balance customer_name ---------- ---------------    500 customer1    400 customer1    500 customer2    900 customer2   6250 customer2   7500 customer3 100000 customer4 

but stuck on getting sum(balance) displaying highest account.

you need group by, order by , limit:

select sum(a.balance) totalbalance, d.customer_name account inner join      depositor d      on a.account_number = d.account_number group d.customer_name order totalbalance desc; 

Comments