UPDATE with LEFT JOIN

thebatfink

Registered User.
Local time
Today, 09:11
Joined
Oct 2, 2008
Messages
33
Hi,

I have a select query..

Code:
SELECT [table1].[field1], [table1].[field2]
FROM [table1]
LEFT JOIN [table2]
ON [table1].[field3]=[table2].[field1]
WHERE [table2].[field2] = true and [table2].[field3] = false;

which works fine and returns the results I want.. But I now want to make that into an UPDATE query which updates the selected records. I have tried this but it gives an error..

Code:
UPDATE [table1]
SET [table1].[field1] = 'N/A', [table1].[field2] = 'N/A'
FROM [table1]
LEFT JOIN [table2]
ON [table1].[field3]=[table2].[field1]
WHERE [table2].[field2] = true and [table2].[field3] = false;

Could anyone explain what the correct syntax should be? I'm assuming I haven't wrote it correctly, but from what I can find 'googling' it looks like it should to me!

Thanks!
 
Hey, thanks very much! That worked :)

The required SQL was..

Code:
UPDATE [table1] 
LEFT JOIN [table2]
ON [table1].[field3]=[table2].[field1]
SET [table1].[field1] = 'N/A', [table1].[field2] = 'N/A'
WHERE ((([table2].field2)=True) AND (([table2].field3)=False));

The brackets around the WHERE statements look a bit excessive, but I can see where I was going wrong now. Thanks for the advice!
 

Users who are viewing this thread

Back
Top Bottom