sql query Update INNER JOINED table
i use INNER JOIN in my 2 tables which is GuestInfo and Reservation
select RoomNo, DateStart, DateEnd, GuestFName, GuestMName, GuestLName
from GuestInfo inner join Reservation
on GuestInfo.GuestID = Reservation.GuestID
now, i want to update that INNER JOINED TABLE
update (select RoomNo, DateStart, DateEnd, GuestFName, GuestMName, GuestLName
from GuestInfo inner join Reservation
on GuestInfo.GuestID = Reservation.GuestID) set EndDate = '1/20/2014'
where GuestFName = 'JAKE'
but this query is error. is this possible?
You should be able to use something similar to this depending on your database.
SQL Server:
update r
set r.DateEnd = '2014-01-20'
from Reservation r
inner join GuestInfo g
on g.GuestID = r.GuestID
where g.GuestFName = 'JAKE'
MySQL:
update Reservation r
inner join GuestInfo g
on g.GuestID = r.GuestID
set r.DateEnd = '2014-01-20'
where g.GuestFName = 'JAKE'
以下语法应该适用于任何数据库:
update reservation
set enddate = '1/20/2014'
where guestid in (select guestId from guestinfo where guestfname = 'Jake')
如果我理解正确,你可以使用:
update reservation
set EndDate = '1/20/2014'
where GuestID in (select GuestID
from GuestInfo inner join Reservation
on GuestInfo.GuestID = Reservation.GuestID
and GuestFName = 'JAKE')
链接地址: http://www.djcxy.com/p/94672.html
上一篇: ALTER TABLE WHERE子句
下一篇: sql查询更新INNER JOINED表