Hello, for example I send to someone some coins and its still unconfirmed, then I send some coins again but now to different address while the previous one is still unconfirmed. Will that affect the the first transaction? What will happen to the both transaction? Thanks in advance for answers
It depends. When you spend bitcoin you spend inputs. Inputs are the coins you have received in the past. Lets make two example to make this clear. We assume no fees, because its easier.
#1 You have received 1 BTC in a single transaction (1 input) in the past.
You now send 0.5 to Bob with TX 1 and send 0.5 back to yourself as change. This is because you only have one input and it larger than what you want to send. The change will confirm when the TX 1 is confirmed. Its not separated. Many wallets will allow you to use unconfirmed change inputs, because they come from yourself and you should be able to trust yourself.
Now you send 0.4 to someone else and have to use the change from TX 1 for it, because you have nothing else left. This 2nd TX needs the 1st TX confirmed in the same or earlier block in order to get confirmed. It will also create change.
#2 You have received 1 BTC in two separate transactions (2 total inputs of 0.5 BTC each) in the past.
You send 0.5 to Bob, there is no change.
You later send 0.5 to Chloe, there is no change either.
Both TX are independent and can confirm in any order.