[Major] SQL & JSP & JavaScript

update, insert문을 select로 가져와서 활용하기

레커 2011. 8. 3. 13:44

- select를 활용한 update 하기
table1 업데이트할 테이블명
table2 업데이트할 데이터를 가져올 테이블명

update table1 a
  set a.column1 = 
    ( select b.column1 from table2 b
          where b.column2 = 'xxx' )
  where a.column3 = 'xxx'; 


- 같은 테이블에서 컬럼 하나만 변경하여 내용 복사해서 넣기
x=col2의 변경코자 하는 값

insert into table a (col1, col2, col3, col4 ..)
    select b.col1, x, b.col3, b.col4 ..
        from table b where col1='조건';