title: Synchronous request with mysql query in nodejs
body: <p>I am working on node.js with express framework and I am trying to call multiple mysql queries and each query depend upon the previous queries.
  How can be execute query in synchronously. </p>
  
  <pre><code>function f1(id, cb) {
      $sql = "SELECT * FROM s1 where process_id=" +id;
  
      connection.query(
          $sql, 
          function (err, result) {         
              if (err) {
                  cb(err, null);
              } else {
                  var str = '';
  
                  if (result.length &gt; 0) {
                      for(val in result) {
                          $sql = "SELECT attribute_name FROM s2 where id=" + result[val].id;
  
                          connection.query(
                              $sql, 
                              function (err, attrresult) {         
                                  if (err) {
                                      cb(err, null);
                                  } else {
                                      if (result.length &gt; 0) {
                                          str  +=  attrresult[0].attribute_name;
                                      }
                                  }
                              }
                          );              
                      }
                  }
  
                  cb('', str);
              }                
          }
      );
  }
  
  router.get('/', function(req, res, next) {  
      f1('27', function (err,respose) {
          console.log(respose);
      });
  });
  </code></pre>
  
  <p>Please suggest. How can we do this.</p>
  
  <p>Thanks in advance.</p>