Я не могу понять, как попасть в другие таблицы с несколькими внешними ключами.
Я получил 2 таблицы:
CREATE TABLE product
(
id SERIAL NOT NULL,
image text,
PRIMARY KEY (id)
);
CREATE TABLE spin_result
(
id SERIAL NOT NULL,
first_slot INT NOT NULL,
second_slot INT NOT NULL,
third_slot INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (first_slot) REFERENCES product(id),
FOREIGN KEY (second_slot) REFERENCES product(id),
FOREIGN KEY (third_slot) REFERENCES product(id)
);
Я хочу получить этот вывод:
|spin_result.id|first_slot.image|second_slot.image|third_slot.image|
Я пробовал это:
SELECT s_r.id,
p.image as "first_slot",
p.image AS "second_slot",
p.image AS "third_slot"
FROM spin_result s_r, product p
WHERE s_r.first_slot = p.id
AND s_r.second_slot = p.id
AND s_r.third_slot = p.id;