복붙노트

[SQL] MySQL은 오류 1093 주위 방법

SQL

MySQL은 오류 1093 주위 방법

1093 개 상태를 업데이트 할 수 없습니다 또는 하위 쿼리 당신이에서 삭제하는 테이블을 조회하는 경우 하위 쿼리를 사용하여 삭제 그 오류가 발생했습니다.

당신은 할 수 없다 그래서

delete from table1 where id in (select something from table1 where condition) ;

좋아, 그 제한을 해결하려면 가장 좋은 방법은 무엇입니까, (당신이 정말로 삭제를 수행하는 하위 쿼리에 필요을 가정하고 완전히 자기 참조 하위 쿼리를 제거 할 수 있습니까?)

편집하다:

여기에 관심이있는 사람들에 대한 쿼리는 다음과 같습니다

mysql> desc adjacencies ;
+---------+---------+------+-----+---------+-------+
| Field   | Type    | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| parent  | int(11) | NO   | PRI | NULL    |       |
| child   | int(11) | NO   | PRI | NULL    |       |
| pathLen | int(11) | NO   |     | NULL    |       |
+---------+---------+------+-----+---------+-------+



-- The query is going to
-- tell all my children to
-- stop thinking my old parents
-- are still their parents

delete from adjacencies
where parent in 
(
-- ALL MY PARENTS,grandparents
  select parent
  from adjacencies
  where child=@me
  and parent!=@me
)

-- only concerns the relations of my
-- grandparents WHERE MY CHILDREN ARE CONCERNED
and child in
(
  -- get all my children
  select child
  from adjacencies
  where parent=@me
)

;

나는 무엇을 시도했다 지금까지 adjsToDelete라는 임시 테이블을 만들고있다 그래서

create temporary table adjsToRemove( parent int, child int ) ;
insert into adjsToRemove...

그래서 지금은 상위 / 하위 쌍의 각 고유 행이 삭제 확인 삭제하는 관계의 컬렉션을 보유하고 있습니다. 하지만 각 쌍을 삭제하는 방법

해결법

  1. ==============================

    1.현재는 테이블에서 삭제하고 하위 쿼리에서 같은 테이블에서 선택할 수 없습니다 - 자세한 내용은

    현재는 테이블에서 삭제하고 하위 쿼리에서 같은 테이블에서 선택할 수 없습니다 - 자세한 내용은

    당신은 삭제에 대한 목표 테이블을 지정할 수 없습니다 수 없습니다

    내 해결 방법 중 하나가 : 조건으로 하위 쿼리에서 삭제 MYSQL

  2. ==============================

    2.나를 위해 일한 http://bugs.mysql.com/bug.php?id=6980에서 발견 된 해결 방법은 항목을 반환 하위 쿼리에 별칭을 만드는 것입니다. 그래서

    나를 위해 일한 http://bugs.mysql.com/bug.php?id=6980에서 발견 된 해결 방법은 항목을 반환 하위 쿼리에 별칭을 만드는 것입니다. 그래서

    delete from table1 where id in 
      (select something from table1 where condition)
    

    로 변경된다

    delete from table1 where id in
      (select p.id from (select something from table1 where condition) as p)
    
  3. ==============================

    3.넌 할 수있어

    넌 할 수있어

    delete t1,t2 
    FROM  table1 t1  
    INNER JOIN 
    table1 t2 ON (t2.something = t1.id);
    

    질문에서 쿼리의 경우,이는 동등해야한다 :

    delete A
    from adjacencies A
    join adjacencies B ON A.parent = B.parent AND B.child=@me AND B.parent != @me
    join adjacencies C ON A.child = C.child AND C.parent=@me
    
  4. ==============================

    4.쉽게 한:

    쉽게 한:

    -- Collect ids
    CREATE TEMPORARY TABLE cleanup_lookup AS 
    SELECT id FROM table1 WHERE condition;
    
    -- Delete the selected records
    DELETE t FROM table1 t INNER JOIN cleanup_lookup l ON t.id = l.id;
    
    -- Temporary tables get dropped when the connection is closed.
    
  5. ==============================

    5.당신은 주저없이이 하나를 사용할 수 있습니다.

    당신은 주저없이이 하나를 사용할 수 있습니다.

    귀하의 질의 :

    delete from table1 
    where id in (select something from table1 where condition);
    

    업데이트 쿼리

    DELETE FROM table1 
    WHERE id IN (SELECT * 
                 FROM 
                     (SELECT MIN(id) FROM table1 GROUP BY Column2) x);
    

    여기에 열 2는 중복 레코드를 발견하고자하는 열입니다.

  6. from https://stackoverflow.com/questions/4484779/mysql-getting-around-error-1093 by cc-by-sa and MIT license