Database

How to MySQL update join with other table

Sometimes we need to update a MYSQL table data based on other table data.

For example order_table field city is NULL, and users_data have a field city, we need to update order_table city from users_table city.

There are many ways to do this, but this query is the simplest one. This sample is for beginner users.

Related Post

Here is working MySQL query to update MySQL table data from other table.

UPDATE 
    order_table LEFT JOIN users_table ON order_table.user_id=users_table.user_id
SET 
    order_table.city = user_table.city,
    order_table.phone_number = user_table.phone_number
WHERE 
    order_table.city IS NULL OR order_table.phone_number IS NULL;

order_table field user_id and users_table field user_id must be indexed for performance.

View Comments

  • table, the query checks the value in the performance column against the value in the performance column in the

Recent Posts

How to fix yum update error thread.error: can’t start new thread

If you found error thread.error: can't start new thread on yum update command on CentOS…

5 months ago

How to securing Cockpit login with Google Two Factor Authenticator 2FA

Cockpit is a web-based graphical interface for servers, intended for everyone, especially those who are:…

8 months ago

How to install Cockpit on CentOS 7 / CentOS 9 Stream and configure Nginx reserve proxy

From cockpit-project.org, Cockpit is a web-based graphical interface for servers, intended for everyone, especially those…

10 months ago

How to install and configure Nginx with HTTP3 on CentOS 9 Stream / RHEL 9

We have been using Nginx with HTTP3 for more than 1 year on our production…

11 months ago

How to sync date time using Crony on CentOS 9 Stream / RHEL 9

On CentOS 7, to sync date time we often use NTPD. But on CentOS 9,…

11 months ago

How to install and enable REMI repository on CentOS 9 Stream

Remi repository is one of third-party repository that have latest update of PHP on Enterprise…

11 months ago