Question

I have a database with three tables; tbl_Room, tbl_Guest and tbl_RoomGuest (a bit simplified).

`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.

I am making a form where I can enter information about a room, and I want to display a list of the guests that have stayed in that room.

How can I select the names from tbl_Guest, when I want to display unique names of only the guests that stayed in that room?

I want the field to be non-editable.

Was it helpful?

Solution

The query to get the unique names could be written using distinct. Here is an example:

select distinct g.GuestName
from tbl_RoomGuest as rg inner join
     tbl_Guest g
     on rg.GuestId = rg.GuestId
where rg.RoomId = YOURROOMIDHERE;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top