Home > Database > Mysql Tutorial > How to Update a Joined Table in MySQL?

How to Update a Joined Table in MySQL?

Mary-Kate Olsen
Release: 2024-12-07 12:02:14
Original
717 people have browsed it

How to Update a Joined Table in MySQL?

MySQL Update a Joined Table

When working with a database, it is often necessary to update records based on multiple conditions from different tables. This can be achieved using join statements. However, the syntax for updating joined tables in MySQL differs from Microsoft SQL Server.

In Microsoft SQL Server, you would start by specifying the table to be updated in the UPDATE statement, followed by join statements and the SET clause. However, in MySQL, the syntax is different. The table to be updated is implicit in the SET clause.

Consider the following dummy example:

UPDATE b
FROM tableA a
JOIN tableB b
   ON a.a_id = b.a_id
JOIN tableC c
   ON b.b_id = c.b_id
SET b.val = a.val+c.val
WHERE a.val > 10
    AND c.val > 10;
Copy after login

In MySQL, this statement will successfully update the b table based on the specified conditions. The FROM clause is not necessary in the MySQL syntax, as the table being updated is determined by the SET clause.

It is important to note that updating joined tables is not part of the standard SQL syntax. MySQL and Microsoft SQL Server have implemented their own extensions to the standard for handling this operation. Therefore, the syntax may vary between different database management systems.

The above is the detailed content of How to Update a Joined Table in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template