There is a table with information about the lobbies in the subway and there is a table with information about the stations themselves:

enter image description here

How do I query between two tables based on the value of a foreign key? For example, select the number of turnstiles (TurnstileCount) at Sokolniki station. Base - PostgreSQL .

    1 answer 1

    This is an implicit INNER JOIN indication, works for SQLite, and maybe works for PostgreSQL))):

     SELECT LOBBY.TurnstileCount FROM LOBBY, STATION WHERE STATION.StationID = LOBBY.StationID AND STATION.Name = "Сокольники" 

    WHERE STATION.StationID = LOBBY.StationID is the key

    This explicit LEFT JOIN indication should work in PostgreSQL, as taken from the tutorial:

     SELECT LOBBY.TurnstileCount FROM LOBBY LEFT JOIN STATION ON STATION.StationID = LOBBY.StationID WHERE STATION.Name = "Сокольники" 

    ON STATION.StationID = LOBBY.StationID is the key

    • 6
      This is an implicit indication of a LEFT JOIN . This is an INNER JOIN . - Akina
    • Yes, you are right, corrected - AtachiShadow
    • one
      'SELECT TurnstileCount.LOBBY ...' need to flip LOBBY.TurnstileCount. Applies to the rest - JavaJunior
    • Yes damn)))) every time I get drunk on it))) All the time I want to write KOLONKA.TABLE))))) - AtachiShadow