Note that there are some explanatory texts on larger screens.

plurals
  1. POSql subquery with inner join
    primarykey
    data
    text
    <p>I've got these tables in my database:</p> <p>Tourist - this is the first table</p> <pre><code> Tourist_ID - primary key Extra_Charge_ID - foreign key name...etc... </code></pre> <p><strong>EXTRA_CHARGES</strong></p> <pre><code> Extra_Charge_ID - primmary key Excursion_ID - foreign key Extra_Charge_Description </code></pre> <p><strong>Tourist_Extra_Charges</strong></p> <pre><code>Tourist_Extra_charge_ID Extra_Charge_ID - foreign key Tourist_ID - foreign key </code></pre> <p><strong>Reservations</strong></p> <pre><code>Reservation_ID - primary key ..... </code></pre> <p><strong>Tourist_Reservations</strong></p> <pre><code>Tourist_Reservation_ID Reservation_ID - foreign key Tourist_ID - foreign key </code></pre> <p>So here is my example: I've got reservation with <code>Reservaton_ID</code> - 27 This reservation has two tourists with <code>Tourist_ID</code> - 86 and <code>Tourist_ID</code> - 87 This Tourist with id 86 has extra charges with <code>Extra_Charge_ID</code> - 7 and and <code>Extra_charge_ID</code> - 11;</p> <p>Is it possible to make sql query and the name and id of the tourist and then all of its extra charges</p> <p>So the output may look like this: </p> <pre><code>Tourist_ID : 86 Name:John Extra_Charge_ID - 7 Extra_Charge_ID - 11 Tourist_ID: 87 Name:Erika Extra-Charge_ID:10 </code></pre> <p>(Here is the query I made to get the extra_charge_description of all of the tourists with Reservation_ID = 27 but I don't know how to change it. to get the names above)</p> <pre><code>Select EXTRA_CHARGES.Extra_Charge_Description,TOURIST_EXTRA_CHARGES.Tourist_ID FROM EXTRA_CHARGES INNER JOIN TOURIST_EXTRA_CHARGES on EXTRA_CHARGES.Extra_Charge_ID = TOURIST_EXTRA_CHARGES.Extra_Charge_ID INNER JOIN TOURIST_RESERVATION on TOURIST_EXTRA_CHARGES.Tourist_ID = TOURIST_RESERVATION.Tourist_ID INNER JOIN RESERVATIONS on RESERVATIONS.Reservation_ID = TOURIST_RESERVATION.Reservation_ID where RESERVATIONS.Reservation_ID=27 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload