如何使用子查询将这些查询合并为 1


 Select * from HotelPerson 
 Where RoomID IN (select ID from HotelRoom Where BookingID = 36 )
 Select * from HotelCancelationPolicy 
 Where RoomID IN (select ID from HotelRoom Where BookingID = 36 )

如何将这两个查询合并为 1 个查询?

这将在一个表中提供两个表中的所有列。

SELECT * 
FROM HotelPerson A, HotelCancelationPolicy B
WHERE A.RoomID = B.RoomID
AND A.RoomID IN (SELECT ID FROM HotelRoom WHERE BookingID = 36)

使用 UNION 获取两个表中所有行的不同元素或UNION ALL

 Select * from HotelPerson 
 Where RoomID IN (select ID from HotelRoom Where BookingID = 36 )
 UNION ALL
 Select * from HotelCancelationPolicy 
 Where RoomID IN (select ID from HotelRoom Where BookingID = 36 )

我想你想连接两个表:

    select * 
      from HotelPerson hp
inner join HotelCancelationPolicy hcp
        on hp.RoomId = hcp.RoomId
     where hp.RoomID IN (select ID 
                           from HotelRoom 
                          where BookingID = 36 )

相关内容

  • 没有找到相关文章

最新更新