user129142: I'm sure I am missing something trivial here but I have a question.
Let's say there are Node A and Node B. We send a transaction to both nodes. Both nodes now contain an unconfirmed transaction in their local mempool.
Node A includes the transaction in the next block with a successful solution. Node B accepts the new block from Node A and continues the chain by creating another new block, including the transaction it received earlier in that next block.
So we have a situation where Node A included the transaction in the first block and Node B included the transaction in the second block. How is this prevented?
I am aware of double spending but the resources I have read usually talk about the same transaction being included in the next block of both nodes but, in that case, one of the blocks would just be discarded.
Thanks.

user13866: 
Node B accepts the new blockchain from Node A and now continues the chain by creating a new block, including the transaction it received earlier in the next block.

When node B accepts the new block from node A, it removes from its mempool all unconfirmed transactions that appear in that block. Node B will only use remaining mempool transactions in its new block.
Node B, and all other nodes, would already have removed from their UTXO lists the inputs consumed by the transaction. This means any new block containing a transaction that attempts to consume the already consumed UTXOs would be seen as invalid.
If node B didn't remove a confirmed transaction from its mempool and produced another block containing a transaction already present in the blockchain, all other nodes would reject node B's new block and node B would not be able to spend the block reward.

user76567: It doesn’t matter if it’s the same or a different block, it’s still a double spend because both transactions spend the same coins.
In your example node B can’t include the transaction in the block because there are no coins to spend.

129142: <p>I'm sure I am missing something trivial here but I have a question.</p>
<p>Let's say there are Node A and Node B. We send a transaction to both nodes. Both nodes now contain an unconfirmed transaction in their local mempool.</p>
<p>Node A includes the transaction in the next block with a successful solution. Node B accepts the new block from Node A and continues the chain by creating another new block, including the transaction it received earlier in that next block.</p>
<p>So we have a situation where Node A included the transaction in the first block and Node B included the transaction in the second block. How is this prevented?</p>
<p>I am aware of double spending but the resources I have read usually talk about the same transaction being included in the next block of both nodes but, in that case, one of the blocks would just be discarded.</p>
<p>Thanks.</p>
 13866: <blockquote>
<p>Node B accepts the new blockchain from Node A and now continues the chain by creating a new block, including the transaction it received earlier in the next block.</p>
</blockquote>
<p>When node B accepts the new block from node A, it removes from its mempool all unconfirmed transactions that appear in that block. Node B will only use remaining mempool transactions in its new block.</p>
<p>Node B, and all other nodes, would already have removed from their UTXO lists the inputs consumed by the transaction. This means any new block containing a transaction that attempts to consume the already consumed UTXOs would be seen as invalid.</p>
<p>If node B didn't remove a confirmed transaction from its mempool and produced another block containing a transaction already present in the blockchain, all other nodes would reject node B's new block and node B would not be able to spend the block reward.</p>
 76567: <p>It doesn’t matter if it’s the same or a different block, it’s still a double spend because both transactions spend the same coins.</p>
<p>In your example node B can’t include the transaction in the block because there are no coins to spend.</p>
