I have a list of elements (Brand + productModel) in the mysql table, and I have a list of Brands in another table.
Example:
table_items
|id| name | brand_id | ----------------------------------- | 1| Apple Mac 15 | | 2| Dell Laptop NXY | | 3| HP Tablet 15 | | 4| Apple Laptop AA | | 5| Dell Tablet VV | | 6| HP Desktop XYZ |
table_brands
|id| name | ------------ | 1| Apple | | 2| Dell | | 3| HP |
I inherited table_items from a previous project, so I need to identify the brand name in table_items if the brand is present, and then add the brand ID to the product column brand_id (currently empty)
, so the ideal solution would be
|id| name | brand_id | ----------------------------------- | 1| Apple Mac 15 | 1 | 2| Dell Laptop NXY | 2 | 3| Dell Tablet 15 | 2 | 4| Apple Laptop AA | 1 | 5| HP Tablet VV | 3 | 6| HP Desktop XYZ | 3
so I donโt know if I should use PHP or can be executed directly in MySQL ... and if PHP, how to determine the corresponding lines?
source share