Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
How to update multiple columns with one query?

I am trying to update multiple columns of a table following an inquirer prompt. I am getting an error following the db.query statement. Here is my code:

function updateEmpRole() {
    db.query(
        'SELECT * FROM role',
        function(err, results) {
            const role = results.map(role => {
                return {name: role.title, value: role.id}
                });
                if (err) throw err;
    db.query(
        'SELECT * FROM employee',
        function(err, results) {
            const employee = results.map(employee => {
                return {name: employee.first_name+' '+employee.last_name, value: employee.id}
                });
                if (err) throw err;
    db.query(
        'SELECT * FROM employee WHERE manager_id IS NULL',
        function(err, results) {
            const manager = results.map(manager => {
                return {name: manager.first_name+' '+manager.last_name, value: manager.id}
                });
                if (err) throw err;
                inquirer.prompt([
                    {
                        type: 'list',
                        name: 'id',
                        message: 'Select an employee to update:',
                        choices: employee
                    },
                    {
                        type: 'list',
                        name: 'role_id',
                        message: 'Please assign a new role:',
                        choices: role
                    },
                    {
                        type: 'list',
                        name: 'manager_id',
                        message: 'Please assign a manager:',
                        choices: manager
                    }
                ])
                .then((response) => {
                    db.query(
                        `UPDATE employee SET role_id = ?, manager_id = ? WHERE id = ?`,
                        response,
                        function(err, results) {
                            console.table('Employee successfully updated.');
                            if (err) throw err;
                            startApp();
                        })
                    })
})})})};

How should I properly specify SET? I only want to update role_id and manager_id.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!