How to update table1 column from table3, with matching id from table2 I have 3 tables - customer, garages, the_cars. With columns like

customer           garages                  the_cars
id | car       owner_id | the_car_id       car_id | car


and need to update the_cars.car with customer.car if customer.car is null, and based by ids. Where customer.id matches with garages.owner_id, find by its garages.the_car_id the the_cars.car_id, and by it finally get the_cars.car and put into customer.car

the code I tried is, don't judge strictly, I'm new to this kind of sql queries

UPDATE `customer` 
SET `customer`.`car` = `the_cars`.`car` 
WHERE (`customer`.`car` IS NULL) 
AND (`customer`.`id` = `garages`.`owner_id`)
AND (`garages`.`the_car_id` = `the_cars`.`car_id`)


I think that will help others too.
Your backticks indicate MySQL, where this syntax works:

UPDATE customer AS c
JOIN   garages  AS g ON g.owner_id = c.id
JOIN   the_cars AS t ON t.car_id   = g.the_car_id
SET    c.car  = t.car
WHERE  c.car IS NULL;


In Postgres you would use a different UPDATE syntax:

UPDATE customer AS c
SET    car  = t.car
FROM   garages  AS g
JOIN   the_cars AS t ON t.car_id = g.the_car_id
WHERE  c.car IS NULL
AND    g.owner_id = c.id;


The FROM clause is not standard SQL.

You have to make sure that the query finds at most one car per customer, or the result is not deterministic.