하은양 믿음군 효실맘 호홍홍집s

다수 Table의 데이터를 하나의 Table로 복사하기 본문

가벼운 배움/MySql

다수 Table의 데이터를 하나의 Table로 복사하기

호홍홍집 2014. 5. 26. 14:43

여러곳의 Table 데이터를
원하는 컬럼만 뽑아서 한 Table에 옮기기..
순번은 자동 증가하게 처리하고....ㅋㅋㅋ

// TB_HOPEHAPPY_BOARD <<=====  INPUT(FLD_NO값은 1씩증가해서 처리) ======== TB_AREA_BOARD, TB_NOTICE_BOARD, TB_HOPE_BOARD

INSERT INTO TB_HOPEHAPPY_BOARD
SELECT CPYFRM.* FROM (
    SELECT @NUM:=@NUM+1 FLD_NO, 
        FRM.FLD_WRITER,FRM.FLD_PWD,FRM.FLD_EMAIL,FRM.FLD_PHONE1,FRM.FLD_PHONE2,FRM.FLD_PHONE3,FRM.FLD_REGINUM1,FRM.FLD_REGINUM2,FRM.FLD_SUBJECT,
        FRM.FLD_CONTENT,FRM.FLD_RESULT,FRM.FLD_FILENAME,FRM.FLD_FILEEXT,FRM.FLD_FILESIZE,FRM.FLD_IMGNAME,FRM.FLD_IMGEXT,FRM.FLD_IMGSIZE,FRM.FLD_COUNT,
        FRM.FLD_DOWNCOUNT,FRM.FLD_POS,FRM.FLD_DEEP,FRM.FLD_NUM,FRM.FLD_PRESS_NAME,FRM.FLD_PRESS_DATE,FRM.FLD_PUBCHK,FRM.FLD_IP,FRM.FLD_REGIDATE,FRM.FLD_MODIDATE
    FROM 
        (SELECT @NUM:=0) AA,
        (SELECT * FROM TB_AREA_BOARD UNION SELECT * FROM TB_NOTICE_BOARD UNION SELECT * FROM TB_HOPE_BOARD) FRM
        ORDER BY FRM.FLD_REGIDATE
    ) CPYFRM
;