Jump to content

Mysql - How to use UPDATE with SELECT???


rahulephp

Recommended Posts

Mysql - How to use UPDATE with SELECT???

 

I have two tables:

1) products_category

-cat_id

-cat_name

 

2) related_category

-rel_cat_id (exaclty same as products_category.cat_id==related_category.rel_cat_id)

-rel_cat_name

 

products_category table

product_category.gif

 

 

related_category table

related_category.gif

 

 

I want to get cat_name from products_category and want to store in rel_cat_name in related_category tabel. and the query should be only one.

 

Not sure how will it works.

I thought it would be something like:

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
)

 

But it doesn't works,

Please assist. Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/209321-mysql-how-to-use-update-with-select/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.