UPDATE employees
SET job_id = (SELECT job_id
FROM employees
WHERE employee_id = 205),
salary = (SELECT salary
FROM employees
WHERE employee_id = 205)
WHERE employee_id = 114;
这是我一直在使用的查询。在这里我使用2个子查询,但它们具有相同的where条件..寻道时间加倍..有没有办法优化整个查询到单个子查询?
提前致谢
答案 0 :(得分:5)
如果更新一组列,则可以删除子查询:
UPDATE employees
SET (job_id, salary)
= (SELECT job_id, salary FROM employees WHERE employee_id = 205)
WHERE employee_id = 114;