Error/DB

[MariaDB]Error Code: 1093. Table 't_co_dept' is specified twice, both as a target for 'INSERT' and as a separate source for data 0.000 sec

IT공부블로그 2019. 4. 24. 10:31
728x90
반응형


Error Code: 1093. Table 't_co_dept' is specified twice, both as a target for 'INSERT' and as a separate source for data

INSERT INTO `t_co_dept` VALUES

(  (select max(dept_seq + 0) + 1  from t_co_dept ) );

위 에러는 해당 테이블에서의 조회된값을 바탕으로 해당테이블을 조작하면 안된다는것 


INSERT INTO `t_co_dept` VALUES

( (select dep from (select max(dept_seq + 0) + 1 as dep from t_co_dept ) a)

위와 같이 별칭을 정해주고 서브쿼리를 이용하면 가능하다


728x90
반응형