I have a tricky (to me, at least) challenge involving a query on 3 different tables to find the:
Study_ID, Study_Name, Price, Sdate on all students in grade.freshman (grade=freshman)
I started trying to piece it together, but I quickly became lost in the complexity. I feel like you need to join, but I can't puzzle it out.
This is as far as I got before getting lost.
SELECT Study_ID, Study_Name, Price, Sdate
FROM Receives
INNER JOIN Study ON Study_ID, Study_Name
INNER JOIN Student ON Grade='freshmen';
Unfortunately, that is it. Here are the tables.
CREATE TABLE Student(
S_ID char(6),
Name varchar(20),
Grade varchar(20),
Age integer,
PRIMARY KEY(S_ID)
);
CREATE TABLE Study(
Study_ID varchar(6),
Study_Name varchar(20),
Label varchar(15),
PRIMARY KEY (Study_ID)
);
CREATE TABLE Receives(
S_ID char(6),
Study_ID char(6),
Sdate date,
Price decimal(5,2),
PRIMARY KEY(S_ID, Study_ID),
FOREIGN KEY(Study_ID)
REFERENCES Study(Study_ID)
);