게시글을 백업하는데.. 쿼리 관련해서 문의드립니다. (select는 나오는데 delete 시 오류)

게시글을 백업하는데.. 쿼리 관련해서 문의드립니다. (select는 나오는데 delete 시 오류)

QA

게시글을 백업하는데.. 쿼리 관련해서 문의드립니다. (select는 나오는데 delete 시 오류)

본문

다중 서브 쿼리를 이용해서, 

일단 

 

select *  from g5_write_abc 

where wr_id  in 

(select wr_id  from g5_write_abc where wr_parent in  

     (select wr_id  from g5_write_abc where wr_1 =2 and wr_is_comment =0) 

); 

 

 

파란색의 조건 wr_1 =2이고 wr_is_comment =0  wr_id를 추출하여 

wr_parent 댓글에 포함된것이 있는지 확인하여 그것만 추출하는 쿼리입니다.

 

이렇게 하면 정상적으로 쿼리가 나옵니다. 

 

 

문제는 delete from g5_write_abc.... 이렇게 하면, 

 

ERROR 1093 (HY000): You can't specify target table 'g5_write_abc' for update in FROM clause 

 

 

어떻게 하면 될까요?

이 질문에 댓글 쓰기 :

답변 2

delete from g5_write_abc where wr_id in (select wr_id from

(select wr_id  from g5_write_abc where wr_parent in  

(select wr_id  from g5_write_abc where wr_1 =2 and wr_is_comment =0)) a) 

버젼에 따라 안되나보네요??

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'in (select wr_id from (select wr_id  from g5_write_abc where wr_parent in ' at line 1


sytnax 에러라는데~!! 어렵군요

create temporary table if not exists temp
select wr_id from g5_write_abc where wr_parent
in (select wr_id from g5_write_abc where wr_1 =2 and wr_is_comment =0);
delete from g5_write_abc where wr_id in ( select wr_id from temp);

쿼리문이 잘못된거 같습니다.

 

delete 문 이하 작성해주셔야 답변 가능합니다.

아 select * from.... 는 정상적으로 쿼리가 되었고요

그래서 delete from g5_write_abc where wr_id  in
(select wr_id  from g5_write_abc where wr_parent in 
    (select wr_id  from g5_write_abc where wr_1 =2 and wr_is_comment =0)
);

이렇게 해서 오류가 난 부분입니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 59,641
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT