Put your "miner theory" hat on.
In theory, a miner could select one tx over another even if the one skipped was willing to pay more. Not only does gas price come into play, but so does gas units. The miner typically wants to squeeze the block full with the highest paying gas prices. But if the lower cost had lower total gas units, then the miner could select that tx to fill the current block if that block was near it's limit.
For more info here's a good article. Feel free to skip down to:
- Transaction is broadcast to the network
and pickup from there.
If you notice the picture above, the miners store all the transactions
in the pool sorted by gas price. The higher the gas price, the more
likely the transaction is included in the next block. This is the
common configuration for a miner node (to optimize for higher pay).
However, a miner can configure her node to sort the transactions
however they like (say they want to help the network by mining only
low gas transactions).
Had a good talk with Sebastian about this one.
So let's define somethings that are currently unclear.
If both transactions are from the same address, the protocol enforces the nonce. So even if the first tx has a lower gas price, it will be and HAS to be included before the later nonce. QnA
- Transaction Execution
If both tx are from different addresses then it is up to the miner in which order they are included in the same block. QnA
Thanks, again, Sebastian for discussing this topic further with me so I can provide a better response :)