title: Node.js API with express & mysql - Redefine fetched parameters for correct column search
body: <p>In my url I want to be able to search column 'active' and 'last_name' ... with the parameters:</p>
  
  <pre><code>active
  name
  </code></pre>
  
  <p>like this:</p>
  
  <pre><code>localhost:4001/api/v1/users/?active=1&amp;name=Peter
  </code></pre>
  
  <p>users.js </p>
  
  <pre><code>var sql = "SELECT * from users";
  var existingParams = ["active", "name"].filter(field =&gt; req.query[field]);
  
  if (existingParams.length !== 0) { 
      sql += ' WHERE ';
      sql += existingParams.map(field =&gt; `${field} = ?`).join(" AND ");
  }       
  </code></pre>
  
  <p>... provides me this:</p>
  
  <pre><code>SELECT * from users WHERE active = ? AND name = ? LIMIT 100 
  </code></pre>
  
  <p>I'm getting an error though ... since the column name in the database is defined 'last_name' ... so I want to end up with sth like this:</p>
  
  <pre><code>SELECT * from users WHERE active = ? AND last_name = ? LIMIT 100 
  </code></pre>
  
  <p>... but keep the search parameter in the url 'name'. How co I need to alter my script?  </p>