执行查询时出现SQL错误

时间:2015-09-23 07:09:55

标签: mysql

我正在尝试运行查询。但它给出了错误。

    Query: UPDATE b SET b.Booking_Date = CURDATE() ,b.Departure_City = 'test', b.Arrival_City = 'test', b.Departure_DateAndTime = CURDATE()...

    Error Code: 1064
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Booking b inner join Booking_Type bt 
    on b.Booking_Id = bt.Booking_Id in' at line 4

查询:

    UPDATE b SET b.Booking_Date = CURDATE() ,b.Departure_City = 'test', b.Arrival_City = 'test',
                b.Departure_DateAndTime = CURDATE(), b.No_Of_Tickets = '5',
                b.Is_Active = 1, b.Modified_Date = CURDATE(), b.Modified_By = 123   
        FROM Booking b INNER JOIN Booking_Type bt 
        ON b.Booking_Id = bt.Booking_Id INNER JOIN Ticket t 
        ON t.Booking_Type_Id =  bt.Booking_Type_Id WHERE t.Ticket_No = 't001'

1 个答案:

答案 0 :(得分:2)

语法错误,使用join更新的正确语法为

update Booking b
INNER JOIN Booking_Type bt ON bt.Booking_Id = b.Booking_Id
INNER JOIN Ticket t ON t.Booking_Type_Id =  bt.Booking_Type_Id
SET
b.Booking_Date = CURDATE(),
b.Departure_City = 'test',
b.Arrival_City = 'test',
b.Departure_DateAndTime = CURDATE(), 
b.No_Of_Tickets = '5',
b.Is_Active = 1, 
b.Modified_Date = CURDATE(), 
b.Modified_By = 123   
WHERE t.Ticket_No = 't001'