Question: Based on the tables below in SQL Write a query to retrieve the composition title, track number and CD title of any composition that appears
Based on the tables below in SQL Write a query to retrieve the composition title, track number and CD title of any composition that appears as multiple tracks on the same CD. Sort the data by composition title (ascending) and track number (ascending). Note that this should include two different recordings of the same composition, such as the two recordings of Countdown that occurs on Giant Steps.
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
Get step-by-step solutions from verified subject matter experts
