簡體   English   中英

從mysql和php中的另一個表更新一個表,其中每列中沒有NULL

[英]Update a table from another table in mysql and php where there are no NULLs in each column

我有下表

TableA.number_id

TableB.number_id

TableA.serial_id

TableB.serial_id

當TableA serial_id == TableB serial_id時,我想用TableB number_id更新TableA.number_id,除非TableA serial_id或TableB serial_id沒有值(即null或空)

這幾乎可行,除了在TableA serial_id和TableB serial_id具有NULL值時會插入第一個number_id時,“ is not NULL”被忽略了。

$sql = "UPDATE TableA, TableB SET TableA.number_id = TableB.number_id WHERE TableA.serial_id = TableB serial_id AND TableA.serial_id IS NOT NULL";

應該執行以下操作:

UPDATE TableA a JOIN TableB b
  ON a.serial_id = b.serial_id
SET
  a.number_id = b.number_id
WHERE a.serial_id IS NOT NULL AND b.serial_Id IS NOT NULL

祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM