My sql 에서 sub query가 안되는 현상 #1093 - You can't specify target table ‘table_name' for update in FROM clause
카테고리 없음 2012. 6. 16. 21:05
Mysql 서버 5.6 을 사용하던 도중, 같은 테이블을 이용해서 sub query 를 날리면 에러가 발생한다. Where 절에서 in, = 모두 에러가 발생한다.
아래 예제는 하나의 테이블안에서 sub query를 이용해서
delete from table_name where incr_id IN ( #1093 - You can't specify target table ‘table_name' for update in FROM clause |
알고 보니.. mysql 정책이 바뀌었다. 헐!!!!
참조 사항 : http://dev.mysql.com/doc/refman/5.6/en/update.html
해결 방법은 두 가지 이다. 하나는 from 절 안에서 서로 비교하는 것 (from table_name as a, table_name as b where a.id = b.id) 과 join 을 이용하는 방법이다.
min(field)를 써야 하기에 두번째 방법을 join을 이용해서 해결했다.
DELETE a |