본문 바로가기

Dev.BackEnd/Mysql

[Mabatis]insert 구문에 select 한 값 집어넣기

보통 Insert 구문은

insert into 테이블 '컬럼' valuse '데이터'

 

insert into 테이블 '컬럼' valuse '데이터'

하지만 데이터에 다른 테이블의 셀렉트한 값을 넣어주고 싶을 땐?

test라는 테이블에 user테이블에서 이름이 손오공인 사람의 아이디와 핸드폰번호를 넣어주고 싶다면?

 

insert
	into
	tb_test ('userId',
	'phone_num')
select
	id,
	phone_num
from
	tb_user
where
	name = '손오공'