title: Rendering view after multiple SELECT queries in Express
body: <p>I'm a bit new in Node.JS and Express framework and I have a great problem with the code below:</p>
  
  <pre><code>app.get('/student', function(req, res) {
      var dbRequest = 'SELECT * FROM Students WHERE IDCard = \'' + req.query['id'] + '\'';
      db.all(dbRequest, function(error, rows) {
          if(rows.length !== 0) {
              /* Save data. */
          }   
          else
              res.render('incorrect_student'); /* Render the error page. */
      });
  
      dbRequest = 'SELECT * FROM Groups WHERE Name = \'' + req.query['group'] + '\'';
          db.all(dbRequest, function(error, rows) {
              /* Add selected data to previous saved data. */
          }
      });
      res.render('student', {data: /* data from both queries above */});
  });
  </code></pre>
  
  <p>As I have written in comment blocks, I would like to: execute first select query, save data from <em>rows</em> object, execute second query, again save received data in other object and then finally render the page passing data from both queries. My question is, what is the best way to do that?</p>
  
  <p>I know that there is a problem caused by anonymous function. I have tried to fix the problem for over five hours as follows:</p>
  
  <ol>
  <li>Clone <em>rows</em> object to another in anonymous function and then pass it to <em>res.render</em>. This solution dosen't work, because values of copied object are not visible (undefined) outside this function - only inside it.</li>
  <li>Render the <em>student</em> page twice - it was really naive of course.</li>
  <li>Change <em>db.all</em> command to <em>db.prepare</em> and then <em>db.run</em> - it wasn't working too.</li>
  <li>Return object by the anonymous function and then assign it to external object defined between <em>app.get</em> and <em>var dbRequest</em>. The result was as described in 1st point.</li>
  </ol>
  
  <p>I have also an idea to create "subpages" containig parts of <em>student</em> page, which need variables from only one query. The other idea is to use some other functions of <em>db</em>, <em>req</em>, <em>res</em> or <em>app</em> objects. But, as I said before, I'm new in Express and I don't know how to realize my above ideas.</p>
  
  <p>Please note that it is impossible to join tables - in fact, I want to make 4-5 queries and then render my view. I'm using SQLite3 database.</p>
  
  <p>Thank you very much for your help! I hope that you'll help me to solve my problem.</p>