title: How to get data from DB (Postgres) in the same order as user input?
body: <p>I have a textarea, where users can enter words separated by comma. For each word I get a translation (data) from my postgres-database. The input as well as the translation from the database are then shown in a table.</p>
  <p><strong>My problem:</strong>
  I need to keep the order of the user input in my table. But the order changes automatically based on the order of the words in my DB. I tried to use ORDER BY, but I couldn't fix it.</p>
  <p>Could someone explain me why the order changes and how to fix it? Thanks a lot!</p>
  <p>Here's my code:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const getTranslation = async(req, res) =&gt; {
    const params = typeof req.query.word === 'string' ? req.query.word : req.query.word.map((_, index) =&gt; `$${index + 1}`);
    console.log(req.query.word);
    
    const rawResults = await pool.query(
      `SELECT "Translation", "Words" FROM "Dictionary" WHERE "Words" IN (${typeof req.query.word === 'string' ? '($1)' : params.join(
        ",")})`,
       typeof req.query.word === 'string' ? [req.query.word] : req.query.word, 
       (error, result) =&gt; {
        if (error) {
          throw error;
        }
        
        res.status(200).json(result.rows); 
        console.log(result.rows);
        }
    );
  
    const wordOrder = req.query.word.split(',');
    
    rawResults.sort((row1, row2) =&gt; {
        return wordOrder.indexOf(row1.Words) - wordOrder.indexOf(row2.Words);
      })
  }
  
  /*terminal console.log(req.query.word) is ['yes', 'no']
  terminal console.log(result.rows) is [ {'Translation': 'non', 'Words': 'no'}, {'Translation': 'oui', 'Words': 'yes'}] */</code></pre>
  </div>
  </div>
  </p>