鍍金池/ 問答/數(shù)據(jù)庫/ Mysql怎么合并兩張表

Mysql怎么合并兩張表

clipboard.png

求問sql語句怎么寫

回答
編輯回答
敢試

獲取最終的值

select a.id, if(a.content is null, b.content, a.content) as content from a left join b on a.link = b.id;

將這個當(dāng)成臨時表,更新 a 即可 (這里寫if,是假設(shè)a表有content字段)

update a as c,
(
  select a.id, if(a.content is null, b.content, a.content) as content 
  from a 
  left join b on a.link = b.id
) as d 
set c.content = d.content 
where d.id=c.id ;
2018年9月2日 15:11
編輯回答
任她鬧
SELECT [Id],[link],ISNULL((SELECT [content] FROM [Table_B] WHERE Id=[Tabe_A].[link]),'')  AS [content] FROM [Table_A] 
2018年1月4日 23:12