title: How to use result array of a query in another query in Mysql+Node JS?
body: <blockquote>
    <p>I want to use the result of first query(sql1) in second query(sql2).  The result of first query(sql1) is getting in .ejs page but no result for the second query(sql2). </p>
  </blockquote>
  
  <pre><code> var sql1 = 'SELECT * FROM `Rooms`';
      con.query(sql1,function(err,rows,fields){
      if(!err)
      {
          var count=rows.length;
          for(i=0;i&lt;count;i++)
          {
              arr_room[i]=rows[i].room_name;
          }
      }
      else
      {
          console.log('error...');
  
      }
    });
  
      var sql2 = 'SELECT * FROM Lights WHERE room_name =? ' ;
      con.query(sql,arr_room[0],function(err,rows,fields){
            if(!err)
            {
                var count=rows.length;
                for(i=0;i&lt;count;i++)
                {
                  arr_icon[i]=rows[i].icon;
  
                }
            }
            else
            {
                console.log('error...');
  
            }
  
       res.render('lighting',{arr_icon,arr_room}); 
      });
  </code></pre>