Rayco
Rayco

Reputation: 117

Select information from different table SQL

SELECT Boeking.reisnummer, (aantal_volwassenen + aantal_kinderen) AS totaal_reizigers
FROM Boeking
WHERE Boeking.reisnummer = Reis.Reisnummer
AND Reis.Reisnummer = Reis.Bestemmingscode;

Table 1 (Boeking) has aantal_volwassen and aantal_kinderen, and Reisnummer. Table 2 (Reis) has Reisnummer and Bestemmingscode.

I have to show the total of aantal_volwassenen and aantal_kinderen. But i also have to show Reis.bestemmingscode which comes from a different table. Currently i have to enter a parameter, how can i solve this?

Upvotes: 0

Views: 31

Answers (1)

Tony
Tony

Reputation: 10357

You need to specify all the tables in the FROM part of your query. The tables should then be joined (JOIN) to get the data you need.

SELECT Boeking.reisnummer
    ,(aantal_volwassenen + aantal_kinderen) AS totaal_reizigers
    ,Reis.Bestemmingscode
FROM Boeking INNER JOIN Reis 
    ON Boeking.reisnummer = Reis.Reisnummer

Upvotes: 1

Related Questions