UPDATE one table column based on another table's column
In one table I have fields
cat_id, cat_name
the table I need to update has several columns but I only want to update one based on the info in the new one.
category
I would like to update the category field to the cat_id of the corresponding name.
in o开发者_StackOverflow中文版ther word
IF
cat_id='66' and cat_name='STACKOVER'
and
category='STACKOVER'
The result should be
category='66'
I'm not sure where to start..
If I understood you,
UPDATE new_category,category SET new_category.category=category.cat_id WHERE new_category.category=category.cat_name
should do the job and lead you toward understanding multi-table updates.
精彩评论