简体   繁体   中英

one-to-one tables relationship, linked by the autonumber in the main table

I have a main table that contain the customers details, I built another table that contain for example a yes/no fields about if the customer paid his taxes, the two tables is linked with autonumber from the main table. I want always to keep them both with the same amount of records (that means every customer has a record in the second table even if the second table has empty record with data only in the primary key field) I need that cause with missing records I cannot run update query to auto fill the second table and i got an error of validation rule violation. I use this sql:

update clients LEFT JOIN MonthlyTbl ON clients.SerialNo = MonthlyTbl.serialno
set sReport04='ready';

I have almost 700 records in the main table and only 80 records in the second, and when I run the sql it updates only 80!!!! Thanks for Help

Please use below query,

update clients set sReport04='ready' where SerialNo in
(select serialno from MonthlyTbl);

here is the right answer first run the sql:

INSERT INTO monthlytbl ( serialno ) SELECT clients.serialno FROM clients WHERE (((clients.[serialno]) Not In (select serialno from monthlytbl)));

and then:

select sreport04 from monthlytbl set sReport04='ready';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM