Question
Based on the tables below in SQL ) Write a query to retrieve the first and last names of all people who both compose music
Based on the tables below in SQL ) Write a query to retrieve the first and last names of all people who both compose music and play tenor sax. Each person should only be listed once in the results.
CREATE TABLE label (
lbltitle VARCHAR(40),
lblstreet VARCHAR(50),
lblcity VARCHAR(30),
lblstate VARCHAR(15),
lblpostcode VARCHAR(12),
lblnation VARCHAR(30),
PRIMARY KEY (lbltitle));
CREATE TABLE cd (
cdid INTEGER,
cdlblid VARCHAR(30),
cdtitle VARCHAR(30),
cdyear INTEGER,
lbltitle VARCHAR(40),
PRIMARY KEY (cdid),
FOREIGN KEY (lbltitle) REFERENCES label(lbltitle));
CREATE TABLE composition (
compid INTEGER,
comptitle VARCHAR(40),
compyear INTEGER,
PRIMARY KEY (compid));
CREATE TABLE recording (
rcdid INTEGER,
rcdlength INTEGER,
rcddate DATE,
compid INTEGER,
PRIMARY KEY (rcdid, compid),
FOREIGN KEY(compid) REFERENCES composition(compid));
CREATE TABLE track (
cdid INTEGER,
trknum INTEGER,
rcdid INTEGER,
compid INTEGER,
PRIMARY KEY (trknum, cdid),
FOREIGN KEY (cdid) REFERENCES cd(cdid),
FOREIGN KEY (rcdid, compid) REFERENCES recording(rcdid, compid));
CREATE TABLE person (
psnid INTEGER,
psnfname VARCHAR(40),
psnlname VARCHAR(40),
PRIMARY KEY (psnid));
CREATE TABLE person_recording (
psnrcdrole VARCHAR(25),
psnid INTEGER,
compid INTEGER,
rcdid INTEGER,
PRIMARY KEY (psnrcdrole, psnid, compid, rcdid),
FOREIGN KEY (psnid) REFERENCES person(psnid),
FOREIGN KEY (rcdid, compid) REFERENCES recording(rcdid, compid));
CREATE TABLE person_composition (
psncomprole VARCHAR(40),
psncomporder INTEGER,
psnid INTEGER,
compid INTEGER,
PRIMARY KEY (psncomprole, psnid, compid),
FOREIGN KEY (psnid) REFERENCES person (psnid),
FOREIGN KEY (compid) REFERENCES composition(compid));
CREATE TABLE person_cd (
psncdorder INTEGER,
psnid INTEGER,
cdid INTEGER,
PRIMARY KEY(psnid, cdid),
FOREIGN KEY (psnid) REFERENCES person(psnid),
FOREIGN KEY (cdid) REFERENCES cd(cdid));
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started