title: SQL function: If Statement dosen't return specific value
body: <p>When I <code>INSERT</code> a User who is already in the Database, then the <code>RETURN &quot;Error_UsernameExist&quot;</code> should trigger but instead I get following Error message from the <code>function</code>: <em>Error Code: 1062. Duplicate entry 'testUser' for key 'Username_UNIQUE'</em></p>
  <p>following function:</p>
  <pre><code>CREATE FUNCTION `registration`(usernameP TEXT, passwordP TEXT, saltP BLOB) RETURNS TEXT
  BEGIN
      IF ((SELECT `Username` FROM `DEV`.`RUser` WHERE `Username` = usernameP) = 1)  THEN
          RETURN &quot;Error_UsernameExist&quot;;
      END IF;
      
      INSERT INTO `DEV`.`RUser` (`Username`, `Password`, `Salt`) VALUES (usernameP, passwordP, saltP);
      RETURN &quot;OK&quot;;
  END
  </code></pre>