>  기사  >  데이터 베이스  >  MySQL Inner Join – Update Values From Another Table_MySQL

MySQL Inner Join – Update Values From Another Table_MySQL

WBOY
WBOY원래의
2016-05-31 08:48:441252검색

Introduction

In this post, we’re going to learn how to update amysql tablecolumn with the values from another table column usinginner join.

Query Syntax

UPDATE [table1_name] AS t1 INNER JOIN [table2_name] AS t2 ON t1.[column1_name] = t2.[column1_name] SET t1.[column2_name] = t2.[column2_name];

Properties

Replace all “[ ]” with the values of your table properties.

  • [table1_name] – This is the name of the table which you’re going to update which is represented as t1
  • [table2_name] – This is the table, from which your’re going to take the values which is represented as t2
  • t1.[column1_name] – This is the column which is going to link two tables (t2.[column1_name]) using inner join
  • t1.[column2_name] – This is the column which is going to be updated with the values from t2.[column2_name]

Example

UPDATE student_marks AS t1 INNER JOIN student_profile AS t2 ON t1.student_id = t2.student_id SET t1.student_name = t2.student_name;

I hope this helps you. Share this post and comment your doubts below if you have any.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.