There is a request to update the salaries of employees who have unpaid orders. There are only 2 such employees, but as a result of the request, the salaries of ALL employees are updated. If we separately execute the SELECT subquery, it returns the necessary workers, but in combination with UPDATE everything works poorly ...

Request Code:

 Query query1 = em.createQuery("UPDATE Employee e SET e.salary = e.salary * 0.8 WHERE e IN ( SELECT DISTINCT e1 FROM Employee e1 INNER JOIN Order o ON e1 = o.employee INNER JOIN OrderItem oi ON oi.order = o INNER JOIN Product p ON oi.product = p WHERE o.isPaid = 0 AND p.id = 13)); query1.executeUpdate(); 
  • Try typing e along with the id, like this ...WHERE e.id IN ( SELECT DISTINCT e1.id FROM... - MrFylypenko
  • So probyval, the result is similar ... - Bogdan Tkachuk
  • @ BogdanTkachuk deleted his answer, since he had nothing to do with jpql. - GreyGoblin

0