Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
PostgreSQL, Inner Join SELECT using three tables

I have three tables in my database; walls, keys and wallAccessKeys.

CREATE TABLE walls (
  id SERIAL PRIMARY KEY,
  name VARCHAR(50)
);

INSERT INTO walls (name)
VALUES ('Test Wall');

CREATE TABLE keys (
    id SERIAL PRIMARY KEY,
    key VARCHAR(50)
);

INSERT INTO keys (key)
VALUES ('testingtesting123');

CREATE TABLE wallAccessKeys (
  id SERIAL PRIMARY KEY,
  keyID INT,
  wallID INT
);

INSERT INTO wallAccessKeys (keyID, wallID)
VALUES (1, 1);

Walls should only be accessible with certain keys, the keys that access each wall is stored in the wallAccessKeys table.

Walls have many keys, keys open many walls.

I'm trying to write an SQL statement to select wall.ID given keys.key value.

I've gotten so far using an Inner Join on wall and wallAccessKeys but can't figure this out.

SELECT *
FROM walls
INNER JOIN wallAccessKeys
ON walls.ID = wallAccessKeys.wallID

Is using Inner join the best way to do this? If so please, could someone help me with the SQL?

To summarize, I need an SQL statement where I can provide a key value e.g. testingtesting123, and get a list of walls that key has access to.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Managed to figure this out using another inner join. Solution bellow if anyone needs it.

SELECT walls.id
        FROM walls
        INNER JOIN wallAccessKeys
        ON walls.id = wallAccessKeys.wallID
        INNER JOIN keys
        ON keys.id = wallAccessKeys.keyID and keys.key = 'testingtesting123'
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda