Here's what must be achieved:
Three tables A,B,C - MySQL innodb
Table C has sales records for items listed in A with supporting info listed in B with a common ID field.

If theres a sale then its inserted to C with the ID of the item.

How do I update same colmn in all three tables even if a sale is not recorded in C hence no ID.

Currently I am selecting from C in one query.
If ID exists then I call script to update all three tables in another query.
If not then I call script to update only two tables.

Select * from C where id ='123'
if result is array
update A,B,C
update A,B

I wish to do this in one query but can seem to wrap my head around using the EXISTS statement.

How do I rewrite the following query to first test if C has a record containing the ID I am looking for and only update A and B if no record but update A,B,C if record exist ?

$sql = sprintf("UPDATE A, B, C
SET A.field ='1',
B.field ='1',
C.field ='1'
AND ='%s'"

With the above script, if theres no record containing the ID in C then this (`B`.`id` = `C.`id`) fails and no tables are updated.