본문 바로가기

Database/MySQL

[MySql] select한 결과를 값으로 CUD 하기 ( insert - select )

 

 

select - insert 

INSERT INTO 들어갈테이블명
(컬럼명1, 컬럼명2, 컬럼명3)
SELECT 컬럼명1, 컬럼명2, 컬럼명3
FROM 조회할테이블명
	insert into tb_post_hist ( 
			post_no
			, hist_type
			, title 
			, content 
		) select
			tp.post_no 
			,  #{postHist}
			, tp.title 
			, tp.content  
		from tb_post tp 
		where tp.post_no = #{postNo}