question

thotels avatar image
thotels asked

SQL Select, join

I need some help on writing the correct select statement...

I have 3 tables (1 reservation can have a primary KidsClubGuest and one KidsClubGuest can have multiple KidsClubChild).


1. KidsClubReservation

2. KidsClubGuest

3. KidsClubChild


I am trying to find a suitable select statement which displays all the KidsClubChild rows where ReservationID = 354 for example.


I have tried this which brings 58 records, thats all the children in the table.

SELECT KCC.* --,KCG.GuestID
FROM KidsClubChild KCC
INNER JOIN KidsClubGuest KCG ON KCC.GuestID = KCG.GuestID


Then the moment I try the below, the return result is 1558 and based on the below if I try to use a where clause then its brings the wrong result set...

SELECT KCC.* --,KCG.GuestID
FROM KidsClubChild KCC
INNER JOIN KidsClubGuest KCG ON KCC.GuestID = KCG.GuestID
INNER JOIN KidsClubReservation KCR ON KCG.GuestID = KCR.GuestID


SELECT KCC.* --,KCG.GuestID
FROM KidsClubChild KCC
INNER JOIN KidsClubGuest KCG ON KCC.GuestID = KCG.GuestID
INNER JOIN KidsClubReservation KCR ON KCG.GuestID = KCR.GuestID
WHERE KCR.ReservationID = 354


selectjoinssqlserver
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.