For every transaction the sum of inputs should be greater than or equal to the sum of outputs (don't spend more than what you got in your wallets).
For equity case, there would be no fee, hence miners have no incentive to include the transaction in the bock (it consumes space, cpu and network bandwidth to include a transaction) but when the sum of inputs is greater than the sum of outputs, miners can take the difference happily, again through coinbase transaction.
It happens in an integral way, i.e. sum of all inputs minus some of all outputs for ordinary transactions included in the block.
Please also note: every single input address/wallet have to be disposed totally even if the owner wishes to transfer just a small fraction of its balance to other party(ies).
In such cases the owner should provide an output of his own (better and more secure: not to be the same as the input) to re-collect the funds he doesn't wish to transfer (or to offer as the fee).
The resulting inconvenience for users to save and manage a lot of public/private keys is ultimately solved by HD wallets: a single pair of master private/public keys used for deducting a series of secondary public/private keys which can be regenerated from the root keys deterministically.
I don't mind too much, but isn't there a more proper place to learn about bitcoin basics? It is a somewhat more advanced subforum, supposed to be at least.