I have the following tables:
CREATE TABLE "itemDetails"
(
id smallint,
name character varying(32) NOT NULL,
description character varying(255) NOT NULL,
PRIMARY KEY (id)
)
CREATE TABLE items
(
id int,
"detailsId" smallint REFERENCES "itemDetails" (id),
"ownerId" int, -- REFERENCES users (id),
"condition" int NOT NULL DEFAULT 100,
PRIMARY KEY (id)
)
The itemDetails
table stores all the static information of an item, while the items
table stores each individual instance of an item, with columns such as the condition
and ownerId
.
If I where to get all items owned by a user by doing the following:
SELECT * FROM items WHERE "ownerId" = 5;
How would I get the name and description of those owned items using the foreign key?