4
I have to update two columns in different tables, but I don’t know the commands very well, I wouldn’t like to use triggers (triggers).
Will be updated around 100 records.
Follow an example:
Table a
id nomes nota
1 SOen etc1
2 SOpt etc2
Table b
id nomes outros
1 SOen i
2 SOen rre
3 SOpt le
4 SOen van
5 SOpt te
That is, when I update a table Row a
all Rows with the same table name a
on the table b
should be updated as well, with the same name changed in the table a
.
Example of the desired update effect:
Update a SET nomes = SOpt_BETAP WHERE nomes = SOpt
Table a
| Updated table with new names
id nomes nota
1 SOen etc1
2 SOpt_BETA etc2
Table b
| Table b is also updated with the new names
id nomes outros
1 SOen i
2 SOen rre
3 SOpt_BETA le
4 SOen van
5 SOpt_BETA te
It would be beneficial for me and other users if I could make a brief explanation of each parameter used as ON
, JOIN
etc, explaining his function there, to those who also have doubts.
It’s a possibility, I don’t know, to minimize the number of connections, and because the code would be cleaner. It doesn’t seem possible, right. I would have done it if I thought it couldn’t be done in just one query.
– Florida
Actually I would use Alternative 1, repeat data so it itches me!
– bfavaretto
I understand, but the way I did, it’s good, it’s like an id, changing the name I could move it associating it to another table etc. It’s simpler, I’ll have to take a lot of bath to avoid this itch. =)
– Florida
But do you understand that if you use the ID, you don’t even need to update table B? Since the name would only be in table A, any query using JOIN will always bring the name updated by crossing A with B!
– bfavaretto
Yes I understand, but to change a whole structure in php... Better leave for next. After I finish it, I’ll think about it, editing the database implies editing another php code... it’s a domino effect. I sweated just thinking about it, but it’s possible.
– Florida