Home >Database >Mysql Tutorial >How to Update a Table Column Using an Inner Join in SQL?
Updating Data from an Inner Join in SQL
Need to update a table column using values retrieved from another table using an inner join? Here's how you can achieve it using SQL syntax:
In your example, you have selected FermentIds from the FERMENT table and joined it with the BELGIUM BEER table. Consider this:
SELECT FERMENT.FermentId FROM FERMENT INNER JOIN [BELGIUM BEER] ON FERMENT.FermentName = [BELGIUM BEER].FermentId ORDER BY [BELGIUM BEER].BeerId
To update a different table (EXAMPLETABLE) using these selected FermentIds:
UPDATE EXAMPLETABLE SET EXAMPLETABLE.FermentId = a.FermentId FROM a (SELECT FERMENT.FermentId FROM FERMENT INNER JOIN [BELGIUM BEER] ON FERMENT.FermentName = [BELGIUM BEER].FermentId ORDER BY [BELGIUM BEER].BeerId) a
However, in Microsoft Access, modify the syntax slightly:
UPDATE FERMENT INNER JOIN ([BELGIUM BEER] ON FERMENT.FermentName = [BELGIUM BEER].FermentId) SET EXAMPLETABLE.FermentColumn = a.FermentColumn
Note:
If you encounter any issues, try using the Query Builder to create the join statement. This step ensures the correct syntax for your specific database system.
The above is the detailed content of How to Update a Table Column Using an Inner Join in SQL?. For more information, please follow other related articles on the PHP Chinese website!