jim tay wrote:
> update flightinfo set seatsAvailible = (seatsAvailible - 13)
> where source Airport = 'Dublin' and destAirport = 'London'
> and flightDate = '2005-05-23 08:30:00'
> and (seatsAvailible - 13) > 0;
>
> I'm just wondering would there be a more elegant way to do this?
This is the correct way to do it, but you have a bug: you will never fill the last seat.
Personally, I would write the last condition as follows:
AND seatsAvailable >= 13
(note the >=)
Also, you need to check wether your update succeeded (maybe another client has taken all the available seats in the meantime). In MySQL 5.x you can use the ROW_COUNT function to do that.
But I would use either transactions or table locking anyway for this kind of application.
--
felix
Please use
BBCode to format your messages in this forum.