Categories: MySQL

Update from one table to another with condition in MySQL

Share

In MySQL, you can update fields of one table from another table with a conditional statement also.

For example, you have two tables i.e. “user_activity” and “user”. And you need to update a column in one table to the value of another column where an user_id matches in both tables.

So, in a single query you can update fields of one table from another table.

UPDATE user_activity, user
SET user_activity.company_id = user.company_id
WHERE  user_activity.user_id = user.user_id

Recent Posts

Unveiling the Truth: Is the Spread of Sinus Infections a Myth or Reality?

Sinus infections, impacting approximately 31 million Americans each year, represent a significant health concern stemming…

1 day ago

Best Exercises To Reduce Weight & Keep You Stronger & Fitter!

No doubt that balanced weight is the key to wellness. So, when it comes to…

1 day ago

ARTIFICIAL INTELLIGENCE: Advantages And Disadvantages? Everything You Need to Know

Pros And Cons Of AI: Artificial Intelligence directly translates to conceptualizing and building machines that…

2 days ago

Four common mistakes when picking an internet provider

We all live on the internet; we use it for everything. Thus, when it comes…

2 days ago

What Is Commonly Misdiagnosed as Pink Eye: Understanding Eye Conditions and Their Symptoms

Introduction: Pink eye, or conjunctivitis, is a common eye condition characterized by redness and inflammation…

2 days ago

Why Flexible Financing is the Future of Small Business

Small businesses are the backbone of the economy. Still, they often face daunting hurdles when…

2 days ago