MySQL如何將乙個表的字段更新到另乙個表中

2021-08-18 23:32:37 字數 387 閱讀 1407

業務:將乙個表的字段更新到另乙個表中;

今天遇到的乙個問題,迷茫了半天,在我記憶中第一種寫法是正確的,但是在mysql中,嘗試半天也不對,(不知道其他資料是否支援),在網上看到有帖子也是這樣的寫法;

第一種寫法:

update t

set t.spu = b.spu

from

table1 t,

table2 b

where

t.vin = b.vin;

折騰半天找資料看到下面 的寫法,可以正常執行;

正確的寫法:

update  table1 t, table2 b

set t.spu = b.spu

where

t.vin = b.vin;

mysql如何將乙個表的資料複製到另乙個表

第一種 未建立表 建立表2,只拷貝表1的結構到表2,不拷貝資料 create table table2 like table1 建立表2,同時拷貝表1的資料和結構到表2 create table table2 select from table1 第二種 已建立表 表2,表1欄位完全匹配 已經建立了...

SQL如何將乙個表的資料插入另乙個表

sql實現將乙個表的資料插入到另外乙個表的 第一種情況的 1 如果2張表的字段一致,並且希望插入全部資料,可以用這種方法 insert into 目標表 select from 表 2 比如要將 articles 表插入到 newarticles 表中,則是 insert into newartic...

MySQL如何將字段內容作為查詢條件

例如 查詢task表中task progress欄位為8,並且建立時間距離當前時間的天數大於arragement valid days欄位中的數字天數。那麼就可以使用contact 函式直接取出字段內容。select r.from t task r where r.task progress 8an...