0

I'm trying to get my head around this SQL question: A database for a hotel chain contains the following tables:

    Hotel(HotelNo, HotelName, City)   
    Room(RoomNo, HotelNo, Type, Price)  
    Booking(HotelNo, GuestNo, DateFrom, DateTo, RoomNo)     
    Guest(GuestNo,  GuestName, GuestAddress)

I want to List the details of all rooms at the Grosvenor Hotel,including the name of the guest staying in the room, if the room is occupied.

I'm okay with joining 2 tables in SQL but I don't know how to go about joining 4 tables.

My attempt would probably be:

SELECT Room.*, Guest.GuestName 
    FROM Room
    INNER JOIN Hotel, Booking, Guest
    ON Hotel.HotelName = "Grosvenor Hotel", Hotel.HotelNo = Room.HotelNo, Booking.GuestNo = Guest.GuestNo;

I think that's completely wrong but anyway, hopefully someone knows what I should be doing. Thanks in advance

2

3 Answers 3

0

The correct syntax is:

SELECT Room.*, Guest.GuestName 
FROM Room
INNER JOIN Hotel on Hotel.HotelNo = Room.HotelNo, 
inner join Booking on Booking.hotelno= Hotel.HotelNo
inner join Guest on Booking.GuestNo = = Guest.GuestNo
where Hotel.HotelName = "Grosvenor Hotel"
0

Try this :

  select g.roomno, g.guestname 

  from hotel h join room r on h.hotelno = r.hotelno
   join booking b on b.hotelno=r.hotelno 
   join guest g on g.guestno=b.guestno

  where h.hotelname='Grosvenor Hotel';
0

you can also try this .. It Will help You

SELECT Room.*, Guest.GuestName FROM Room
INNER JOIN Hotel on Hotel.HotelNo = Room.HotelNo, 
join Booking on Booking.HotelNo= Hotel.HotelNo
join Guest on Booking.GuestNo = Guest.GuestNo
where Hotel.HotelName = "Grosvenor Hotel"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.