sqlite更新

qingjiawen發表於2024-10-09

sqlite更新欄位

UPDATE tab1
  SET field1 = field1 || '-',
      field2 = field2 + 1
  WHERE ID < 10

UPDATE tab1
  SET (field1, field2) = (field1 || '-', field2 + 1)
  WHERE ID < 10

表關聯更新

UPDATE tab1
  SET field1 = (SELECT tab2.field3 FROM tab2 WHERE tab2.FID = tab1.ID),
  WHERE EXISTS (SELECT * FROM tab2 WHERE tab2.FID = tab1.ID)

UPDATE tab1
  SET (field1, field2) = (SELECT tab2.field3, tab2.field4 FROM tab2 WHERE tab2.FID = tab1.ID)
  WHERE EXISTS (SELECT * FROM tab2 WHERE tab2.FID = tab1.ID) 

相關文章