compare and update

  • Thread starter Thread starter Tinyc
  • Start date Start date
T

Tinyc

Guest
I have two tables in an Access database tb1 contains a unique field the same as tb2 (the master table). I am attempting to compare both unique fields and if the are trhe same value, update tb2 from a different column value in tb1

tb1
ID Date_left
1 01/01/2004
2 01/02/2004

tb2 Date_left
1
2

I'm new to SQL and need to update table 1 regularly without over writing any other data. All of the other queries work fine. Any suggestions please?

Tinyc
 
update tbl2 (listoffieldstoupdateseparatedbycomma)
Select listoftablesandfieldstouseseparatedbycomma
From tbl1

Example
Code:
Update tbl2 ( dte_left )
Select tbl1.dte_left
From tbl1 left join tbl2 on tbl1.id=tbl2.id
where not tbl2.id is null;

Have a search on sql statement building for more info.
If you are experimenting with access, copy the mdb file before trying the sql statements.


Vince
 
What else?

update tbl2 (listoffieldstoupdateseparatedbycomma)
Select listoftablesandfieldstouseseparatedbycomma
From tbl1

Example
Code:
Update tbl2 ( dte_left )
Select tbl1.dte_left
From tbl1 left join tbl2 on tbl1.id=tbl2.id
where not tbl2.id is null;
Have a search on sql statement building for more info.
If you are experimenting with access, copy the mdb file before trying the sql statements.


Vince

Have tried your suggestion, thank for this but its still showing an error with the front bracket on Date_left
I had made a copy and already searched for info on the update. I've enclosed my query in the hope I've added a bracket/space in the wrong place.

Tiny

update tracking ( Date_Left )
Select Leavers.Date_Left
From Leavers left join tracking on Leavers.id=tracking.id
where not tracking.id is null;
 

Users who are viewing this thread

Back
Top Bottom