괴발개발 성장기

Study/Mysql

[Mysql] Error Code: 1093. You can't specify target table 'p' for update in FROM clause 에러메시지 해결 방법

지니유 2022. 6. 10. 09:36
반응형

# 배경

SQL문 update할 때 where절에 서브쿼리를 했다. 그런데 에러 메시지가 나타났다.

 

# 에러메시지

Error Code: 1093. You can't specify target table 's' for update in FROM clause

 

# 문제의 SQL문

update sell s set s.date='20220601' 
where s.id in (select a.id from 
review r inner join sell a on r.application_id = a.id  
where r.member_id  in (2, 5, 6, 7));

update 할때 테이블를 서브쿼리로 사용하여 문제가 생겼다.

 

# 해결 방안

서브쿼리로 만든 데이터를 임시 테이블을 만들어서 조건을 적었다.

update sell s 
set s.date='20220601' 
where s.id in (select id from ((select a.id from 
review r inner join sell a on r.application_id = a.id  
where r.member_id  in (2, 5, 6, 7)) tmp_table);

 

 

 

 

반응형