【问题标题】:"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 'WHERE"“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以在“WHERE”附近使用正确的语法
【发布时间】:2022-06-14 21:47:36
【问题描述】:

我正在尝试更新 MySQL,但每次运行时都会出错。我错过了什么?我查看了所有有类似错误的帖子,我所做的每一次更改都会遇到同样的错误。

“您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'WHERE = lastName = 'zuniga', roleID = 2' 附近使用正确的语法",

我试过了:

"UPDATE employees SET ?"

它只会更新列表中的每个人。不仅仅是我要更新的个人。

function updateEmployeeRole() {
  connection.query("SELECT employees.lastName, role.title FROM employees JOIN role ON employees.roleID = role.id;", 
  (err, res) => {
          if (err) throw err;

          inquirer.prompt([
              {
                  name: "lastName",
                  type: "rawlist",
                  choices: function () {
                      var lastName = [];
                      for (var i = 0; i < res.length; i++) {
                          lastName.push(res[i].lastName);
                      }
                      return lastName;
                  },
                  message: "What is the employee's last name? ",
              },
              {
                  name: "role",
                  type: "rawlist",
                  message: "What is the employee's new title? ",
                  choices: selectRole()
              },
          ]).then(function (answers) {
              var roleId = selectRole().indexOf(answers.role) + 1;
              connection.query("UPDATE employees SET WHERE ?",
                  {
                      lastName: answers.lastName,
                      roleID: roleId
                  },
      
                  function (err) {
                      if (err)
                          throw err;
                      console.table(answers);
                      startProcess();
                  });
          });
      });
}

【问题讨论】:

  • 去掉第2行末尾的分号。

标签: javascript mysql


猜你喜欢
  • 1970-01-01
  • 2022-01-24
  • 2021-08-06
  • 2022-01-14
  • 2011-08-07
  • 2015-09-20
  • 2015-03-30
  • 2012-05-02
相关资源
最近更新 更多