데이터 베이스

mysql row가 여러개인 update 문

멋진 개구리 2021. 4. 1. 17:10
반응형
#attched_file테이블에  bs_idx값이 없는곳에 bs_idx를 넣어준다
update attached_file af1,
	(
	select bb.BS_IDX, bb.B_IDX , af.idx, af.img_path
	from attached_file af 
	inner join bbs_board bb 
	on af.idx=bb.B_IDX 
	) af2
set af1.BS_IDX = case when af1.BS_IDX is null then af2.BS_IDX else af1.BS_IDX  end
where af1.IMG_PATH =af2.img_path;

첨부파일 테이블에 게시판 번호가 없어서 업데이트를 어떻게 할까 고민하다가 올림

 

[출처]thinkerodeng.tistory.com/201

반응형