title: How to create a function that will return a friend's id. The friend table has two primary keys and one foreign key id from the user table
body: <p>I tried this way:</p>
  <pre><code>CREATE FUNCTION `num_friends`(id int) RETURNS int(11)
      DETERMINISTIC
  BEGIN
      declare res int;
  
      select id 
      into res 
      from friendship 
      where `id_friend` = id or `id_user` = id;
  
      return (res);
  END
  </code></pre>