IT/DataBase

[MySQL/MariaDB] Update join...

์•Œ ์ˆ˜ ์—†๋Š” ์‚ฌ์šฉ์ž 2022. 11. 29.

 

MySQL/MariaDB updae join... ๐Ÿ˜…

mysql์—์„œ ํ…Œ์ด๋ธ”์„ ์กฐ์ธํ•ด์„œ update๋ฅผ ์‹คํ–‰ํ•ด์•ผ ๋˜๋Š” ๊ฒฝ์šฐ ์•„๋ž˜์ฒ˜๋Ÿผ ์กฐ์ธํ•ด์„œ ์—…๋ฐ์ดํŠธ๋ฅผ ํ•˜๋ฉด ๋œ๋‹ค.

์ž์ฃผ ์“ฐ์ผ ๋“ฏ ํ•˜๋‹ˆ ๋ฉ”๋ชจ ํ•ด๋‘ 

-- mainTable๊ณผ subTable์„ no๋กœ ์กฐ์ธํ•œ ๋’ค no๊ฐ€ ๊ฐ™์€ ๋ฐ์ดํ„ฐ๋งŒ use_yn๊ฐ’์„ 'Y'๋กœ ๋ณ€๊ฒฝ
-- (์–‘์ชฝ ๋ชจ๋‘ ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋งŒ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด inner join ์‚ฌ์šฉ)
update mainTable a inner join subTable b on a.no = b.no 
set a.use_yn = 'Y'
where a.no = b.no 
;

๋Œ“๊ธ€