I have the following SQL tables which describe a relation where users can rate books:
CREATE TABLE Users
(
UID INT PRIMARY KEY,
Username VARCHAR(256),
DoB DATE,
Age INT,
);
CREATE TABLE Book
(
ISBN VARCHAR(17) PRIMARY KEY,
Title VARCHAR(256),
Published DATE,
Pages INT,
Language VARCHAR(256)
);
CREATE TABLE Rating
(
UID INT REFERENCES Users (UID),
ISBN VARCHAR(17) REFERENCES Book (ISBN),
PRIMARY KEY (UID,ISBN),
Rating INT
)
I want to get a list of book-titles with a rating of 5 that ALLOWS REPETITIONS for every rating. For example, if Book "A" has three ratings of 10, then its tile "A" should be in the list three times.
My idea is to extract the "isbn" from the primary key "(uid,isbn)" from rating and then select the respective titles. So I wrote the code that selects all "(uid,isbn)" tuples:
select (uid,isbn)
from rating
where rating = 10
However, I do not know how to access the isbn part from there. Could you please tell me how to do this?