I must be overlooking something simple. I'm setting a variable from a query result in a MySQL stored procedure like this:
SELECT @myName := username FROM User WHERE ID=1;
So, @myName is storing the username of userid 1, which is 'Paul'. Great.
But later in the stored procedure I run an update on this record:
UPDATE User SET username = 'Fred' WHERE ID=1;
Now, for some reason, @myName = 'Fred' when it should still equal 'Paul', right? It appears MySQL is just creating a pointer to the record rather than storing a static value in the @myName variable.
So in short, I want to be able to store a value in a variable from a query result and assure the value of my variable doesn't change, even when the data in the table it was set from changes.
What am I missing? Thanks in advance!