MySQL에서 CRUD / CREATE, UPDATE, DELETE, SELECT를 할 때 같은 테이블을 사용할 수 없다.
그래서 아래와 같은 에러가 발생한다.
문제 발생
Error 1093 (ER_UPDATE_TABLE_USED) SQLSTATE = HY000
Message = "You can't specify target table 'x' for update in FROM clause"
해결 방법 [sample 1을 sample 2처럼 변경_alias(as)별첨을 추가]
SAMPLE 1
update table_a
set no = 'a'
where seq in (select seq from table_a where x = 'b' )
SAMPLE 2
update table_a
set no = 'a'
where seq in ( select * from ( select seq from table_a where x = 'b' ) as temp )
반응형
'코딩 | 개념 정리 > MySQL' 카테고리의 다른 글
[MySQL] Can't find target attribute Error (0) | 2021.08.19 |
---|---|
[MySQL] SQL Error [1067] [42000]: Invaild default value for... (0) | 2021.02.10 |
[MySQL] into outfile형태로 export시 컬럼명이 없다! (0) | 2021.02.05 |
[MySQL] 에러와의 싸움... 흔한 에러 모음 (0) | 2021.02.05 |
[Mysql] export 시도 중 secure_file_priv 문제 발생!! (0) | 2021.02.05 |