当前位置: 首页 > 面试题库 >

Update column based on matching values in other table in mysql

施季
2023-03-14
问题内容

I have two tables calendar and customer table. Calendar table have a
“customer” column which has customer table “ID” as value. But unfortunately,
this calendar customer field value was wrongly populated with other values.
Both tables have these common fields Date, SeatingID and BusID. How to update
the calendar table customer field based on these common fields?.

Below is the structure of both tables.

Customer Table enter image descript<a href=ion here" src="https://imgs.xnip.cn/cj/l/11/c9a25393-96da-4c4f-b2c3-ded891bcdee7.jpg" />

calendar Table

enter image description here


问题答案:
update calendar ca left join customer c 
on c.DateofTravel=ca.Date and c.SeatingID=ca.SeatingID and c.BusID=ca.BusID 
set 
ca.Customer=c.ID;


 类似资料:

相关阅读

相关文章

相关问答