Question

a. Write five select statements to select data from each table individually. b. Write one select...

a. Write five select statements to select data from each table individually.

b. Write one select statement with joins to list the playlist name, playlist track number, song name, artist name, album name, sorted by playlist name and playlist track number.

DROP TABLE Artists CASCADE CONSTRAINTS;
DROP TABLE Albums CASCADE CONSTRAINTS;
DROP TABLE Songs CASCADE CONSTRAINTS;
DROP TABLE Playlists CASCADE CONSTRAINTS;
DROP TABLE PlaylistSongs CASCADE CONSTRAINTS;


CREATE TABLE Artists (
ArtistID int NOT NULL,
ArtistName varchar(255),
PRIMARY KEY (ArtistID)
);

CREATE TABLE Albums(
AlbumID int NOT NULL,
AlbumName varchar(255),
YearReleased int,
ArtistID int NOT NULL,
PRIMARY KEY (AlbumID)
);

CREATE TABLE Songs(
SongID int NOT NULL,
SongName varchar(255),
TrackNumber int,
AlbumID int NOT NULL,
PRIMARY KEY (SongID)
);

CREATE TABLE Playlists(
PlaylistID int NOT NULL,
PlaylistName varchar(255),
PRIMARY KEY(PlaylistID)
);

CREATE TABLE PlaylistSongs
(
PlaylistID int NOT NULL,
SongID int NOT NULL,
PlaylistTRackNumber int,
PRIMARY KEY(PlaylistID,SongID)
);


INSERT INTO Artists (ArtistID, ArtistName)
VALUES ('1', 'Primus');
INSERT INTO Artists (ArtistID, ArtistName)
VALUES ('2', 'Captain Murphy');
INSERT INTO Artists (ArtistID, ArtistName)
VALUES ('3', 'King Krule');

INSERT INTO Albums (AlbumID, AlbumName, YearReleased, ArtistID)
VALUES ('1', 'Sailing the Seas of Cheese', '1991', '1');
INSERT INTO Albums (AlbumID, AlbumName, YearReleased, ArtistID)
VALUES ('2', 'Frizzle Fry', '1990', '1');
INSERT INTO Albums (AlbumID, AlbumName, YearReleased, ArtistID)
VALUES ('3', 'Duality', '2012', '2');
INSERT INTO Albums (AlbumID, AlbumName, YearReleased, ArtistID)
VALUES ('4', '6 Feet Beneath the Moon', '2013', '3');

INSERT INTO Songs (SongID, SongName, TrackNumber, AlbumID)
VALUES ('1', 'John The Fisherman', '6', '2');
INSERT INTO Songs (SongID, SongName, TrackNumber, AlbumID)
VALUES ('2', 'Jerry was a Race Car Driver', '5', '1');
INSERT INTO Songs (SongID, SongName, TrackNumber, AlbumID)
VALUES ('3', 'Tommy the Cat', '9', '1');
INSERT INTO Songs (SongID, SongName, TrackNumber, AlbumID)
VALUES ('4', 'The Killing Joke', '9', '3');
INSERT INTO Songs (SongID, SongName, TrackNumber, AlbumID)
VALUES ('5', 'Out Getting Ribs', '13', '4');

INSERT INTO Playlists (PlaylistID, PlaylistName)
VALUES ('1', 'Putting in Work');
INSERT INTO Playlists (PlaylistID, PlaylistName)
VALUES ('2', 'Relaxing');

INSERT INTO PlaylistSongs (PlaylistID, SongID, PlaylistTRackNumber)
VALUES ('1', '1', '1');
INSERT INTO PlaylistSongs (PlaylistID, SongID, PlaylistTRackNumber)
VALUES ('1', '2', '2');
INSERT INTO PlaylistSongs (PlaylistID, SongID, PlaylistTRackNumber)
VALUES ('2', '4', '1');
INSERT INTO PlaylistSongs (PlaylistID, SongID, PlaylistTRackNumber)
VALUES ('2', '5', '2');

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a. Write five select statements to select data from each table individually.

a.1 Select all details of the albums which is released after 2000.

select * from Albums where YearReleased > 2000;

Number of Records: 2

AlbumID AlbumName YearReleased ArtistID
3 Duality 2012 2
4 6 Feet Beneath the Moon 2013 3

a.2 Give the artists detail whose name is not Primus.

select ArtistId, ArtistName from Artists where ArtistName != 'Primus';

Number of Records: 2

ArtistID ArtistName
2 Captain Murphy
3 King Krule

a.3 Display the song name and song tack number where song name is equal to Tommy the Cat or album id is greater than 3.

select SongName, TrackNumber from Songs
where SongName = 'Tommy the Cat' or AlbumID > 3;

Result:

Number of Records: 2

SongName TrackNumber
Tommy the Cat 9
Out Getting Ribs 13

a.4 Give all the details of the playlist whose id is 1.

select * from Playlists where PlaylistID = 1;

Number of Records: 1

PlaylistID PlaylistName
1 Putting in Work

a.5 Provide the total number of songs in the playlist songs.

select count(*) from PlaylistSongs;

Number of Records: 1

count(*)
4

b. Write one select statement with joins to list the playlist name, playlist track number, song name, artist name, album name, sorted by playlist name and playlist track number.

select PlaylistName, PlaylistTRackNumber, SongName, ArtistName, AlbumName from Playlists
inner join PlaylistSongs on PlaylistSongs.PlaylistID = Playlists.PlaylistID
inner join Songs on Songs.SongID = PlaylistSongs.SongID
inner join Artists on Artists.ArtistID = Albums.ArtistID
inner join Albums on Albums.AlbumID = Songs.AlbumID;

Number of Records: 4

PlaylistName PlaylistTRackNumber SongName ArtistName AlbumName
Putting in Work 1 John The Fisherman Primus Frizzle Fry
Putting in Work 2 Jerry was a Race Car Driver Primus Sailing the Seas of Cheese
Relaxing 1 The Killing Joke Captain Murphy Duality
Relaxing 2 Out Getting Ribs King Krule 6 Feet Beneath the Moon
Add a comment
Know the answer?
Add Answer to:
a. Write five select statements to select data from each table individually. b. Write one select...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help in SQL management studio please. Question: Create the same query as query 5,...

    I need help in SQL management studio please. Question: Create the same query as query 5, but only include artists if they have 'Pop' Genre. Previous question: Create a list of all composers and artists in your database. Include two columns in your record set (the names of the returned columns are in brackets): 'Composer/Artist Name' and 'Type' (which will indicate whether your results are from the composer or artist table). Order by 'Composer/Artist Name'. This is the answer for...

  • Based on the CREATE TABLE statements, make an ER model of the database. Give suitable names...

    Based on the CREATE TABLE statements, make an ER model of the database. Give suitable names to the relationships. (Remember cardinality and participation constraints.) The diagram must use either the notation used in the textbook (and the lectures) or the crow’s foot notation. To save you some time: There are a few tables that include the following address fields: Address, City, State, Country and PostalCode (and the same fields with the prefix Billing-). You are allowed to replace these attributes...

  • SQL Create a database called MyMusician Create three tables, one named “User”, one named “Song”, and...

    SQL Create a database called MyMusician Create three tables, one named “User”, one named “Song”, and one named “Playlist”. The “User” table should have a column for userID (integer, autoincrement, not null, primary key), username, and password. It should also have one column for a foreign key we will assign later called “playlistID” (integer). The “Playlist” table should have a “playlistID” (integer, autoincrement, not null, primary key), and a column for a foreign key we will assign later called “songID”...

  • Use the SQL statements provided to create your tables. Write one SQL statement for each of...

    Use the SQL statements provided to create your tables. Write one SQL statement for each of the following problems. You can only use the conditions listed in the tasks. E.g., in task 1, you cannot manually look up pid of Information Systems undergraduate program. Here is the given code: drop table textbook_schedule cascade constraints; drop table textbook_author cascade constraints; drop table schedule cascade constraints; drop table course cascade constraints; drop table textbook cascade constraints; drop table author cascade constraints; drop...

  • --- Paper Review drop table paper_review cascade constraint; drop table paper_author cascade constraint; drop table paper...

    --- Paper Review drop table paper_review cascade constraint; drop table paper_author cascade constraint; drop table paper cascade constraints; drop table author cascade constraints; drop table reviewer cascade constraints; create table reviewer ( rid int, --- reviewer id rname varchar(50), --- reviewer name remail varchar(50),-- reviewer email raffiliation varchar(50),-- reviewer affiliation primary key (rid) ); insert into reviewer values(1,'Alex Golden', '[email protected]','UMBC'); insert into reviewer values(2,'Ann Stonebraker', '[email protected]','UMD'); insert into reviewer values(3,'Karen Smith', '[email protected]','UMB'); insert into reviewer values(4,'Richard Wallas', '[email protected]','UMBC'); insert into...

  • Help In Database: Next comes the data entry: Make up data for your database, or find...

    Help In Database: Next comes the data entry: Make up data for your database, or find real data. You can enter the data with INSERT statements, but it is much easier to use PhpAdmin. It has a form where you can type the data directly. Alternatively, you can use PhpAdmin to import CSV data (comma-separated values), which you can export from Excel. Include at least 3 rows in each of the entity relations, and as many rows as you need...

  • Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring...

    Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring 2019. Use an explicit cursor to print out the titles and prices of textbooks for these two courses. Sample code to create the tables: drop table textbook_schedule cascade constraints; drop table textbook_author cascade constraints; drop table schedule cascade constraints; drop table course cascade constraints; drop table textbook cascade constraints; drop table author cascade constraints; drop table teacher cascade constraints; drop table program cascade constraints;...

  • I am trying to delete these tables from my data base and I keep getting: "mysql>...

    I am trying to delete these tables from my data base and I keep getting: "mysql> DROP TABLE Courses; ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails" I am using the command DROP TABLE Courses; Below is my sql file use sdev300; // Create a student table CREATE TABLE Students ( PSUsername varchar(30) primary key, FirstName varchar(30), LastName varchar(30), EMail varchar(60) ); CREATE TABLE Courses( CourseID int primary key, CourseDisc varchar(4), CourseNum varchar(4),...

  • drop table department cascade constraints; create table department ( Dname   varchar2(15)   not null, Dnumber int   not...

    drop table department cascade constraints; create table department ( Dname   varchar2(15)   not null, Dnumber int   not null, Mgr_ssn   char(9)   not null, mgr_start_date   Date, primary key (Dnumber), Unique    (Dname)); insert into DEPARTMENT values ('Research', '5', '333445555', '22-May-1988'); insert into DEPARTMENT values ('Administration', '4', '987654321', '01-Jan-1995'); insert into DEPARTMENT values ('Headquarters', '1', '888665555', '19-Jun-1981'); drop table employee cascade constraints; create table employee ( Fname   varchar2(15) not null, Minit   char(1), Lname   varchar2(15) not null, Ssn   char(9), Bdate   date, Address   varchar2(30), Sex   char(1),...

  • Given the bsg_planets table created by using the following definition query : -- CREATE TABLE `bsg_planets`...

    Given the bsg_planets table created by using the following definition query : -- CREATE TABLE `bsg_planets` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `population` bigint(20) DEFAULT NULL, `language` varchar(255) DEFAULT NULL, `capital` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 Insert information about the planet Mars which has a population of 2,  language as "Binary" and "Olympus Mons" as Capital, in bsg_planets. Then list the row(s), with all the information for that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT