Update table column based on another table values

All we need is an easy explanation of the problem, so here it is.

I have two tables:
Table 1:

1          0               5
2          0               3
3          0               1
4          0               2

Table 2:

1          A               
2          C               
3          B               
4          B

Is there any scenario where I can use UPDATE to update Table 1.TICKET_AGENT field by searching through ORIGINAL_ID as the ID of Table 2 and if ORIGINAL_ID is found in table 2, update table 1 after with the corresponding TICKET_AGENT value?

UPDATE: ORIGINAL_ID points to ID in table 2

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You can just do a joined update

update table1
inner join table2 on table2.ID = table1.ORIGINAL_ID
set table1.TICKET_AGENT = table2.TICKET_AGENT

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply