我有这些表:
customer:
customer_id vat_number
=========== ==========
1 ES-0000001
2 ES-0000002
3 ES-0000003
invoice:
invoice_id customer_id vat_number
========== =========== ==========
100 1 NULL
101 3 NULL
102 3 NULL
103 2 NULL
104 3 NULL
105 1 NULL
我想用invoice.vat_number中的当前值填充invoice.vat_number中的NULL值.是否可以使用单个SQL语句执行此操作?
我到目前为止触发了语法错误:
UPDATE invoice
SET vat_number=cu.vat_number /* Syntax error around here */
FROM invoice iv
INNER JOIN customer cu ON iv.customer_id=cu.customer_id
WHERE invoice.invoice_id=iv.invoice_id;