我尝试同时更新3个表。 clients.id> cars.client_id> works.car_id是无法实现的
UPDATE clients, cars, works
JOIN cars on cars.client_id = clients.id
JOIN works on works.car_id = cars.id
SET clients.name = '15-adsadadadsa' ,
clients.email = '15-aaa@aa.com' ,
clients.phone = '15-3232131',
clients.email = '15-aaa@aa.com' ,
cars.reg = 'aaa-aaa' ,
cars.model = 'aaa-aaa' ,
cars.year = '111111' , works.work = 'aaaa' WHERE works.id = '15';
但是得到错误
不唯一的表/别名:'cars'
谢谢你的帮助!
答案 0 :(得分:1)
这是因为x[a][t] == 1
表被提及两次(在cars
以及UPDATE
中),如果它们是JOIN
,则无需提及UPDATE
中的表名称在JOIN
中,试试这个:
UPDATE clients
JOIN cars on cars.client_id = clients.id
JOIN works on works.car_id = cars.id
SET clients.name = '15-adsadadadsa' ,
clients.email = '15-aaa@aa.com' ,
clients.phone = '15-3232131',
clients.email = '15-aaa@aa.com' ,
cars.reg = 'aaa-aaa' ,
cars.model = 'aaa-aaa' ,
cars.year = '111111' , works.work = 'aaaa' WHERE works.id = '15';