title: MySQL Stored Procedure - IF EXISTS ... THEN returning unexpected result
body: <p>The below is my Stored Procedure(Routine) to check whether or not a <strong>user with Username(input)</strong> exists in the database. 
  Inside the database, I already <strong>have a user with Username - 'dev'.</strong>
  However, when I ran the below routine, it returned me with <strong>res = 1</strong>, which I <strong>expected it to be -1</strong>. </p>
  
  <p>I called the routine this way. Please correct me too if I am calling it the wrong way. I am really new to MySQL Routines.</p>
  
  <blockquote>
    <p>CALL usp_GetUserValidation ('dev', @ErrorCode)</p>
  </blockquote>
  
  <p>Can any MySQL Routine pros here enlighten me on this? Thank you in advance guys :)</p>
  
  <pre><code>DELIMITER $$
  CREATE PROCEDURE usp_GetUserValidation(IN `@Username` VARCHAR(255), OUT `@ErrorCode` INT)
      LANGUAGE SQL
      NOT DETERMINISTIC
      CONTAINS SQL
      SQL SECURITY DEFINER
      COMMENT 'To validate user login'
  BEGIN
  
      IF EXISTS
      (SELECT UserID 
          FROM mt_User
          WHERE UserName = @Username)
      THEN
              SET @ErrorCode = -1;
  
  
      ELSE
          SET @ErrorCode =  1;
  
      END IF;
  
  
      SELECT @ErrorCode AS res;
  
  END$$
  DELIMITER ;
  </code></pre>