我有一个包含三个表的数据库; tbl_Room
,tbl_Guest
和tbl_RoomGuest
(稍微简化)。
`tbl_Room` has information about a certain room
`tbl_Guest` has information about a certain guest
`tbl_RoomGuest` has information about what guest stayed at which room,
and the dates they stayed.
我正在制作一个表格,我可以输入有关房间的信息,我想显示留在那个房间的客人名单。
当我想只显示留在那个房间的客人的唯一名字时,如何从tbl_Guest
中选择姓名?
我希望该字段不可编辑。
答案 0 :(得分:0)
可以使用distinct
编写获取唯一名称的查询。这是一个例子:
select distinct g.GuestName
from tbl_RoomGuest as rg inner join
tbl_Guest g
on rg.GuestId = rg.GuestId
where rg.RoomId = YOURROOMIDHERE;