E
E
EVOSandru62015-12-21 08:49:04
MySQL
EVOSandru6, 2015-12-21 08:49:04

How to update the value of a field in mysql relative to another field's relationship?

Good afternoon,
I want to transfer data from a link table to the main one ( m_products.photo = mc_photo.id )
Created a new text field photo_var
Tried such a query, but caught

UPDATE m_products
SET photo_var = mc_photo.name
from mc_photo
WHERE m_products.photo = mc_photo.id;

I catch:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from mc_photo WHERE m_products.photo = mc_photo.id' at line 3
How to fix the query?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Mokhov, 2015-12-21
@EVOSandru6

If I'm not mistaken, it's like this:

UPDATE m_products, mc_photo
SET m_products.photo_var = mc_photo.name
WHERE m_products.photo = mc_photo.id;

see example below

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question