Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

374
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda