Join specific columns from 3 specific tables (SQL SERVER 2012)

  • Hi all,

    I'm new to SQL and would like to join specific columns that form part of 3 specific tables (GuestNameInfo, GuestStaySummary, ResrvationStay).

    The common column (not necessarily the Primary Key or Foreign Key) found in all the above 3 tables is called "ReservationStayID".

    I've been able to write the query to join 2 tables (see below) but can't find the right syntax to join the 3 tables.

    The columns needed for the 3rd table (ie: Reservation Stay) are AdultCount, ChildCount, SourceCode.

    Select a.FirstName,a.LastName,a.ArrivalDate,a.DepartureDate,a.CreatedOn,b.ProfileId,b.ReservationStatus,b.MarketSegmentCode,b.Nights,b.GuestCount

    From GuestNameInfo a

    JOIN GuestStaySummary b on a.ReservationStayID = b.ReservationStayID

    Thank you for your help!

  • Select a.FirstName,a.LastName,a.ArrivalDate,a.DepartureDate,a.CreatedOn,b.ProfileId,b.ReservationStatus,b.MarketSegmentCode,b.Nights,b.GuestCount,c.AdultCount, c.ChildCount, c.SourceCode

    From GuestNameInfo a

    JOIN GuestStaySummary b on a.ReservationStayID = b.ReservationStayID

    JOIN ResrvationStay c on c.ReservationStayID = b.ReservationStayID

    hope it helps

  • It works!! Thanks a lot, twin.devil!:-)

  • u r welcome

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply