title: MySQL error, "Not allowed to return a result set from a function"?
body: <p>I'm trying to wrap my head around functions in mySQL and I'm currently making one that checks the column <code>account_description</code> and it's value to see if the description already exists.</p>
  
  <p>If it does exist already, display a message saying so. However, if the description is not there, display a different message saying that it is not found.</p>
  
  <p>Thanks!</p>
  
  <p>MySQL Code:</p>
  
  <pre><code>DROP FUNCTION IF EXISTS test_glaccounts_description
  
  DELIMITER //
  
  CREATE FUNCTION test_glaccounts_description
  (
      check_description VARCHAR(50)
  )
  RETURNS VARCHAR(50)
  BEGIN
  
  DECLARE var_check VARCHAR(50);
  
  SELECT
      account_description INTO var_check
  FROM
      general_ledger_accounts
  WHERE
      account_description = check_description;
  
      IF var_check = check_description THEN
          SELECT 'That description already exists.';
      ELSEIF var_check != check_description THEN
          SELECT 'That description does not exist.';
      END IF;
  
  RETURN var_check;
  
  END //
  
  DELIMITER ;
  
  SELECT
      test_glaccounts_description(account_description) as 'Check'
  FROM 
      general_ledger_accounts
  WHERE
      account_description = 'Accounting';
  </code></pre>