![](/img/trans.png)
[英]Update all the records of a field in a table whose value is only in another table
[英]Update table records if values match records value in another table
我有兩張桌子
Table1
Date Number Name Memo PaidAmount
2012-02-13 122361 John Doe some memo 245.25
2014-06-29 146352 Steve Doe another memo 360.34
Table2
Date FileNumber Name Address Price Status
2012-02-13 122361PH John Doe some memo 245.25 Pending
2014-06-29 146352AP Steve Doe another memo 360.34 Pending
我只需要在FileNumbers的前六位與“ Table1”中的“ Number”的前六位匹配的記錄中,將“ Table2”中的記錄的狀態從“待處理”更新為“已關閉”。
這就是我的腦海...
UPDATE Table2
SET Status = Closed
Where Table2.FileNumber (first six digits) = Table1.Number (first six digits)
這就是您可以做到的。
update
Table2
inner join
Table1 on SUBSTRING(Table1.Number,1,6) = SUBSTRING(Table2.FileNumber,1,6)
SET Table2.Status = 'Closed'
UPDATE Table2
INNER JOIN Table1 ON substr( Table2.number, 1, 6 ) = substr( Table1.number, 1, 6 )
SET STATUS = 'Closed'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.