Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

368
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!