title: MySQL returning value from a SELECT statement
body: <p>I keep getting this error:
  <strong>Result consisted of more than one row</strong></p>
  
  <p>I have this function:</p>
  
  <pre><code>DROP FUNCTION IF EXISTS db.GetUserIDByCourseID;
  CREATE FUNCTION db.`GetUserIDByCourseID`(CourseID int) RETURNS int(11)
  BEGIN
        SELECT (c.user_id + COALESCE(pi.user_id, 0) + COALESCE(p.user_id, 0))
          INTO @user_id
          FROM courses c
               LEFT JOIN users u
                  ON u.user_id = c.user_id
               LEFT JOIN partners p
                  ON p.partner_id = c.partner_id
               LEFT JOIN partners_individual pi
                  ON pi.individual_id = c.individual_id;
               WHERE c.course_id = CourseID;
  
        SELECT user_type_id
          INTO @user_type_id
          FROM users
         WHERE user_id = @user_id;
  
        RETURN @user_type_id;
     END;
  </code></pre>