I have read that entire bitcoins received in one transaction have to be spend in other transaction. The actual amount to be transferred is deducted from the total bitcoins and the change is returned back to sender's bitcoin address.
Suppose, David Sends Alice the amount in form of two outputs, output0: 10 bitcoins and output1: 20 bitcoins in the same transaction. Now Alice wants to transfer 5 bitcoin to Eve. Does Alice has to spend entire 30 bitcoins, by transfering 5 to Eve and remaining 25 to herself?
Or can she choose any of the output e.g. output0: 10, transfer 5 bitcoins to Eve and change 5 bitcoins to herself? If this is the case, how is this tracked, as the hash of the David's transaction can be used to spend the output1: 20 bitcoins.