2

我在我的 2 个表中使用 INNER JOIN,即 GuestInfo 和 Reservation

select  RoomNo, DateStart, DateEnd, GuestFName, GuestMName, GuestLName
from GuestInfo inner join Reservation
on GuestInfo.GuestID = Reservation.GuestID

现在,我想更新那个 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'

但这个查询是错误的。这可能吗?

4

3 回答 3

4

根据您的数据库,您应该能够使用与此类似的东西。

SQL 服务器:

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'
于 2013-02-27T20:14:20.427 回答
2

以下语法应适用于任何数据库:

update reservation
    set enddate = '1/20/2014'
    where guestid in (select guestId from guestinfo where guestfname = 'Jake')
于 2013-02-27T20:16:09.173 回答
0

如果我理解正确,您可以使用:

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') 
于 2013-02-27T20:17:35.000 回答