Categories
JavaScript Answers

How to run multiple statements in one query with node-mysql?

Spread the love

To run multiple statements in one query with node-mysql, we call the query method.

For instance, we write

connection.query("SELECT ?; SELECT ?", [1, 2], (err, results) => {
  if (err) {
    throw err;
  }

  console.log(...results);
});

to call query with the select statements separated by a semicolon.

the array are the values that fill the question mark placeholders.

And we get the results from the results array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *