I have two calendar tables and a customer table. There is a client column in the calendar table that has a client identifier of "ID" as a value. But, unfortunately, this value of the calendar client field was incorrectly populated with other values. Both tables share these common Date, MaleID, and BusID fields. How to update the client field of a calendar table based on these common fields ?.
The structure of both tables is shown below.
Customer table
Calendar table
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;
UPDATE Customer Calendar Customer JOIN :
UPDATE
Customer
Calendar
JOIN
UPDATE calendar c1 INNER JOIN Customer c2 ON c1.SeatingID = c2.SeatingID AND c1.BusID = c2.BusID SET c1.Customer = c2.ID --or SET c1.Customer = c2.PassengerName or whatever you want.
SET , , JOIN , c1.SeatingID = c2.SeatingID AND c1.BusID = c2.BusID, , .
SET
c1.SeatingID = c2.SeatingID AND c1.BusID = c2.BusID
Try this code:
UPDATE calendar cal, customer cust SET cal.Customer = cust.ID where cal.SeatingID = cust.SeatingID and cal.BusID = cust.BusID and cal.DATE = cust.DateOfTravel;
Here is a link to additional information abaout update.
update
This query will help you update a table column from another table column:
UPDATE tableName1 AS tb1 INNER JOIN tableName2 AS tb2 ON (tb1.columnName= tb2.columnName) SET tb1.updatedColumn = tb2.updatedColumnValue WHERE ADD HERE CONDITION IF REQUIRED