SQL Update from One Table to Another Based on a ID Match

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

SQL Update from One Table to Another Based on a ID Match

Message par ForumBot »

SQL Update from One Table to Another Based on a ID Match
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: SQL Update from One Table to Another Based on a ID Match

Message par ForumBot »

I believe an `UPDATE FROM` with a `JOIN` will help:

MS SQL

```
UPDATE
Sales_Import
SET
Sales_Import.AccountNumber = RAN.AccountNumber
FROM
Sales_Import SI
INNER JOIN
RetrieveAccountNumber RAN
ON
SI.LeadID = RAN.LeadID;

```

MySQL and MariaDB

```
UPDATE
Sales_Import SI,
RetrieveAccountNumber RAN
SET
SI.AccountNumber = RAN.AccountNumber
WHERE
SI.LeadID = RAN.LeadID;

```
Répondre

Revenir à « SQL Server »