title: nodejs-async: return mysql query result in for loop
body: <p>I have three operations to do one after another</p>
  
  <p>1.Fetch some rows from db</p>
  
  <p>2.Another mysql query in forloop for getting some data and store in variable</p>
  
  <p>3.Display the data</p>
  
  <p>For that i am using <code>async</code> <code>waterfall</code> method.</p>
  
  <pre><code>async.waterfall([
              function(callback){
                  //first sql and pass the result to second function
                  collection.getAllCollections(function (status,error,result) {
                      callback(null,result);
                  });
              },
             //running another query in loop with result with previous
              function(result, callback){
                  for(var i=0;i&lt;result.length;i++){
                      collection.getImages(result[i].id,function (status,error,user) {
                          //append the query result to old result
                           result[i]['users'] = user;
                      });
                  }
                  callback(null,result);
              }
          ], function (err, result) {
  
              console.log("result",result);
          });
  </code></pre>
  
  <p>But the problem final <code>result</code> does not contains the <code>user</code> results because the second query(query in for loop is asynchronous)</p>