Update values in Table A based on sorting results from Table B (MySQL) -


first - in advance looking , possibly helping, appreciated!

basically need sort table a, column descript, a~z , then...

based on sort, update table b, column printorder lowest sort value have printorder = 1 , highest sort value have printorder = 20,000

in subset of data lowest 18681 & highest 18695. (actual table range 1 20,000)

the data should modified printorder in table b.

here subset of data table a:

    inum    descript     23151   crayon apron     23152   acrylic bunny acry153     23153   acrylic easter egg acry154     23154   acrylic posypot tulip acrye01a     23155   acrylic orn chick acrye02     23156   hat baby chick bge10151     23157   sipper baby chick bge10158     23158   grow chick ea10991     23159   nail crystals easter ea11052     23160   mug jelly bean em11681     23161   plush tumbleweed chick he10148 

here subset of data table b:

    id      inum    printorder     142161  23151   18681     144054  23161   18683     145092  23159   18687     145093  23160   18688     145094  23152   18689     145095  23153   18690     145096  23155   18691     145097  23154   18692     145098  23158   18693     145099  23156   18694     145100  23157   18695 

here hoped result:

    id      inum    printorder     142161  23151   18681     144054  23161   18694     145092  23159   18693     145093  23160   18692     145094  23152   18689     145095  23153   18683     145096  23155   18687     145097  23154   18688     145098  23158   18690     145099  23156   18691     145100  23157   18695 

thanks & happy new year!

this might work. first set counter (i) go 1 20000 (if have 20000 rows). use update ... join ... order pattern sort descript, @ point can set printorder sequential number. hope works you.

set @i:=1;  update b b    join     (    select a.inum, descript       descript <> ''    order descript ) on b.inum = a.inum set b.printorder=@i:=@i+1; 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -