title: MySQL Create stored function that can declare and set select results
body: <p>I would like to gather the ids from two tables, merge those tables to use them an IN statement to find out the count(*) like so:</p>
  
  <pre><code>   drop function if exists listing_count;
     create function listing_count(parent int(11)) returns int(11) deterministic 
     begin 
      declare count int(11) default 0;
      declare ARRAY1;
      declare ARRAY2;
      set ARRAY1=(select id from category1); 
      set ARRAY2=(select id from category2); 
      set count=(select count(*) from listing_category where category in(ARRAY1+ARRAY2));
      return count;
     end
  </code></pre>
  
  <p>Is it possible to set and declare selected results (ARRAY1 and ARRAY2) to use later on? <strong>I don't want to merge everything into a single query</strong>.</p>