title: How to fix two Knex MySQL queries dependent on each other in a router.get
body: <p>I am attempting to display data from two database tables on a route using Node, Express and JavaScript. I have connected my Express app to the database using knex, and am attempting to use MySQL SELECT queries to elicit data from the two tables to display on the server.</p>
  
  <p>The data in the 'column' attribute/column in the 'offence_columns' table appears as a column in the 'offences' table, hence why I have two promises, one in which takes the data from the 'column' attribute in the 'offence_columns' table, and the other in which selects the 'area' attribute in the 'offences' table and another attribute/column that is what was selected from the 'columns' attribute.</p>
  
  <p>Since 'column' is a reserved word in MySQL, I have had some issues in selecting it. Using single quote marks like in the code provided provides me with a code in the terminal:</p>
  
  <blockquote>
    <p>Unhandled rejection Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as <code>0</code> from <code>offences</code>' at line 1.</p>
  </blockquote>
  
  <p>I get the same error if I substitute the single quotes for back ticks (<code>column</code>), but if I try using both ('<code>column</code>') I get a different error:</p>
  
  <blockquote>
    <p>Error: ER_BAD_FIELD_ERROR: Unknown column '<code>column</code>' in 'field list'.</p>
  </blockquote>
  
  <p>I tried using aliases but it didn't seem to help.</p>
  
  <pre><code>router.get('/api/search/:offence', function(req, res, next) {
    req.db.from('offence_columns').select('column').where('pretty',"=",req.params.offence)
      .then((rows) =&gt; {
        req.db.from('offences').select('area', rows)
          .then((rows2) =&gt; {
            res.json({"Error" : false, "Message" : "Success", "City" : rows2})
          })
      })
      .catch((err) =&gt; {
        console.log(err);
        res.json({"Error" : true, "Message" : "Error in MySQL query"})
      })
  });
  </code></pre>