반응형

[MYSQL] update ...select 구문. 삽질하다가 OK

#mysql #database #update #select

아래처럼 해야함.

update wp_moa_bible_mcheyne m

  join wp_moa_bible_sort s on s.name_short = m.sort_name

   set m.ever_seq_no = s.ever_seq_no

;

아래처럼 계속 하면 삽질만 한다. 

update wp_moa_bible_mcheyne a

set ever_seq_no = (

    select ever_seq_no

      from wp_moa_bible_sort b

    where a.sort_name = b.name_short

);



update wp_moa_bible_mcheyne m,

        wp_moa_bible_sort s

    set m.ever_seq_no = s.ever_seq_no

  where m.sort_name = s.sort_name

;
반응형

+ Recent posts