-1
I have a question in my work regarding locating and replacing a certain field, updating it with a value of a search.
I’ll give you an example:
I have this table that has LOC_NUM_SUB and note in the image above that 13 does not have MUN_NU, but the LOC_NU of another record already has. I need to search in this table LOC_NUM based on LOC_NUM_SUB and fill the LOC_NO_SUB MUN_NUB which is null.
Here is another example from the same table:
In this, note, that is several LOC_NU_SUB with MUN_NU null. And there is a LOC_NU with MUN_NU, accurate, again: fill the MUN_NU with the value found in LOC_NU.
I tried the following SQL statement:
UPDATE cepdb.log_localidade A2 SET MUN_NU = (SELECT A2.MUN_NU FROM cepdb.listacep A1 INNER JOIN cepdb.log_localidade A2 ON (A1.LOC_NUM_SUB = A2.LOC_NU) WHERE cepdb.listacep.LOC_NUM_SUB IS NOT NULL AND cepdb.log_localidade.LOC_NU = cepdb.listacep.LOC_NU) Error Code: 1054. Unknown column 'cepdb.listacep.LOC_NUM_SUB';
But returns me error.
That I need to update another table that has LOC_NUM and MUN_NU only:
Where the MUN_NU is null, we need to put the correct code, relative to it.
Thanks in advance.