mysql - Update data from one table to another -


i have small problem updating rows of 1 table data one, please help.

table l columns

make model oemnumberlatest oemnumberprevious cstockcode cdescription 

the 2 columns cstockcode,cdescription blank @ moment , waiting populated, , second table c columns stockcode , description

the question how move/copy contents of table c rows of table l?

where c.stockcode = l.oemnumberlatest , or c.stockcode = l.oemnumberprevious

you shouldn't move contents of 1 table other. better values when need them, using join:

select l.*, c.cstockcode, c.cdescription table1 l join      c      on c.stockcode = l.oemnumberlatest or c.stockcode = l.oemnumberprevious; 

this seems strange condition, or because can multiple matches.

in case, can convert update easily:

update table1 l join        c        on c.stockcode = l.oemnumberlatest or c.stockcode = l.oemnumberprevious     set l.cstockcode = c.cstockcode,         l.cdescription = c.cdescription; 

when both conditions match, 1 arbitrarily used update.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -