Mysql - How to use UPDATE with SELECT???
I have two tables:
1) products_catego ry
-cat_id
-cat_name
2) related_categor y
-rel_cat_id (exaclty same as products_catego ry.cat_id==rela ted_category.re l_cat_id)
-rel_cat_name
products_catego ry table

related_categor y table

I want to get cat_name from products_catego ry and want to store in rel_cat_name in related_categor y tabel. and the query should be only one.
Not sure how will it works.
I thought it would be something like:
But it doesn't works,
Please assist. Thanks in advance
I have two tables:
1) products_catego ry
-cat_id
-cat_name
2) related_categor y
-rel_cat_id (exaclty same as products_catego ry.cat_id==rela ted_category.re l_cat_id)
-rel_cat_name
products_catego ry table

related_categor y table

I want to get cat_name from products_catego ry and want to store in rel_cat_name in related_categor y tabel. and the query should be only one.
Not sure how will it works.
I thought it would be something like:
Code:
UPDATE related_category SET related_category.rel_cat_name = ( SELECT product_category.cat_name FROM product_category INNER JOIN related_category ON related_category.rel_cat_id = product_category.cat_id )
Please assist. Thanks in advance
Comment