title: MySQL: SET Variable in if exists condition
body: <p>I am trying to set the variables while checking the if exists condition.
  I have used <strong>:=</strong> to set the variables, however, it for some reason it seems that when I try to set the variable in the if exists condition, it displays the result for the previous query. 
  Following is the code snippet from the stored procedure. </p>
  
  <pre><code>if exists (select @AccountVerified := AccountVerified, @IsActive := IsActive  from tblUserLookUp where UserName = inUserName) then
          begin
              select "1: From if condition", @AccountVerified, @IsActive;
  
              select @AccountVerified := AccountVerified, @IsActive := IsActive  from tblUserLookUp where UserName = inUserName;
              select "2: From select condition", @AccountVerified, @IsActive;
              select @AccountVerified, @IsActive;
  
              if @AccountVerified = 0 then
                  set outErrorCode = 3;
              elseif  @IsActive = 0 then
                  set outErrorCode = 4;
              end if;
          end;
      else
          set outErrorCode = 1;
      end if;
  </code></pre>
  
  <p>I observed this by trying to print the values through the select statement after the if condition and after again running the select query on the table. 
  The </p>
  
  <blockquote>
    <p>2: From select condition</p>
  </blockquote>
  
  <p>seems to display the actual current results
  However, </p>
  
  <blockquote>
    <p>1: From if condition</p>
  </blockquote>
  
  <p>seems to display the value from previous query. </p>
  
  <p>Is there any concept of variable caching or it is that you cannot set variables in the if condition? I am also open to any other recommendation that you might have. </p>
  
  <p>The only reason to do this is to save that select query on the same table as that of the if exists select query. </p>