2016. 8. 24.

Table 'name' is specified twice, both as a target for 'DELETE' and as a separate source for data

select 문으로 가상테이블을 하나 생성하고 as 로 별명을 설정해서 셀렉트 해 오면 됩니다.

Table 'name' is specified twice, both as a target for 'DELETE' and as a separate source for data 

이와 같은 에러는

delete from table where num in (select num from table);

같은 테이블을 조회해서 같은 테이블에 결과를 적용하려고 할 때 나는 에러입니다. 이럴 때에는 가상의 alias 를 줘서 처리하면 간단히 빠져나갈 수 있습니다.
같은 메모리상의 값을 조회하면서 변경하려고 해서 일어나는 일 같습니다.

delete from table where num in (select * from (select num from table)) stm;

이렇게 stm 이라는 alias 를 만들어주면 에러를 회피할 수 있습니다.

댓글 없음:

댓글 쓰기