MS Access 2013 - 如何从另一个表中选择唯一值?

时间:2014-04-23 12:20:02

标签: sql ms-access ms-access-2013

我有一个包含三个表的数据库; tbl_Roomtbl_Guesttbl_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中选择姓名?

我希望该字段不可编辑。

1 个答案:

答案 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;