5
I’m not able to update one table with another’s select.
I have a table mdl_user which contains several columns and created another users_sg to copy some columns.
I copied with
INSERT INTO
  users_sg (id, username, firstname, lastname)
SELECT
  id, username, firstname, lastname FROM mdl_user
I wanted to keep updating, but I could only do one column and one user at a time:
UPDATE
  users_sg
SET
  users_sg.username = (SELECT username FROM mdl_user where id=3)
WHERE id=3
I have to update the fields username, firstname and lastname of all users at once?
The update will be periodic, or when it is changed in one table you want it to update automatically in the other?
– Celso Marigo Jr
@Celsomarigojr I think it’s for once.
– Jorge B.
@Jorgeb. but in this case the Insert would already solve!?
– Celso Marigo Jr
@Celsomarigojr because maybe, is a little confused. Fabio can explain?
– Jorge B.
The answer helped?
– Marco Souza
Hi, I will need to run the command at least once a day to update the ones that already exist.
– Fabio