插入到具有两个 where 条件的选择语句中



我在SQL中有两个类似的表。FixedDetails 和 TempFixedDetails。现在我想从固定细节更新临时固定详细信息的第二行。谁能帮我查询?

固定细节:

ID  Itemdescription   Date
1   Lenovo           4/9/2014
2   Idea             5/7/2015

临时固定详细信息 :

ID  Itemdescription Date
1   Lenovo          4/9/2014
2   Null             null

假设tempfixed_details中的ID列是唯一的,则可以执行以下操作:

你没有提到你的DBMS,所以以下是标准的ANSI SQL:

update tempfixed_details
set (itemdescription, date) = (select fd.itemdescription, fd.date
from  fixed_details fd
where tempfixed_details.id = fd.id)
where itemdescription is null
and date is null;

使用join尝试以下操作

update TempFixedDetailst t2 set t2.Itemdescription=t1.Itemdescription, t2.Date=t1.Date
INNER JOIN  
Fixeddetails t1 on t2.id=ti.id

最新更新