MySQL: update table A when elements from table B fulfill some requirements

31 views Asked by At

I'm developing an e-commerce website and I need to run an SQL command that update the category of all products that have a category beginning with 'HP '.
There is a table PRODUCT with all products, a table CATEGORY with all categories and a table PRODUCT_CATEGORY that links product_id and category_id.

The tables link are:

PRODUCT
product_id
icecat_category

PRODUCT_CATEGORY
category_id
product_id

CATEGORY
category_id
category_name

The update I would like to perform is:
search all the PRODUCT.product_id that have a CATEGORY.category_name LIKE 'HP %' and for these items modify the PRODUCT_CATEGORY.category_id and set it to the CATEGORY.category_id where CATEGORY.category_name = PRODUCT.icecat_category.

I am sure it is more difficoult to explain rather to create the right SQL statement, I hope I've been clear enough.

I'm working with:

  • MySQL 8.0
  • Joomla 4.4.3
  • HikaShop 5.0.3
0

There are 0 answers