Below is the Update query for the question 11.1:
UPDATE songs
SET artist_id = (
SELECT artist.id
FROM artist
WHERE artist.name = songs.artist
);
Below is the Update query for the question 12.1;
UPDATE songs
SET genre_id = (
SELECT genre.id
FROM genre
WHERE genre.name = songs.genre
);
Explanation :
In the above queries the columns artist_id and genre_id of table songs is updated by using Update statement and SUBQUERY in which select statement is used to get the genre id and artist id from the genre and artist tables by using the condition where genre names and artist names are equal to respective names in the songs table.
Please refer to the snapshot below for the above update queries:
Explanation :
Three tables are created with the below description:
1) Table1 : artist
Column names: id , name
Query for creating and inserting the sample data in table artist :
CREATE TABLE artist(id integer PRIMARY KEY, name varchar(50));
INSERT INTO artist VALUES(1,'Taylor_swift');
INSERT INTO artist VALUES(3,'Maroon5');
INSERT INTO artist VALUES(4,'Queen');
INSERT INTO artist VALUES(5,'Strauss');
2) Table1 : genre
Column names: id , name
Query for creating and inserting the sample data in table genre:
CREATE TABLE genre(id integer PRIMARY KEY, name varchar(50));
INSERT INTO genre VALUES(10,'Pop');
INSERT INTO genre VALUES(30,'Rock');
INSERT INTO genre VALUES(40,'Classical');
INSERT INTO genre VALUES(50,'Funk');
2) Table1 : songs
Column names: id , title, artist, minutes, seconds, sales, genre, artist_id, genre_id
Query for creating and inserting the sample data in table songs:
CREATE TABLE songs(id integer PRIMARY KEY, title varchar(50), artist varchar(50), minutes integer, seconds integer, sales float, genre varchar(50), artist_id integer, genre_id integer);
INSERT INTO songs
VALUES(1,'Love','Taylor_swift',3,41,0.00,'Pop',0,0);
INSERT INTO songs
VALUES(3,'Maps','Maroon5',3,5,0.00,'Pop',0,0);
INSERT INTO songs
VALUES(4,'Under_Pressure','Queen',3,46,0.00,'Rock',0,0);
INSERT INTO songs
VALUES(5,'Blue_Danube','Strauss',3,58,0.00,'Pop',0,0);
Please refer to the snapshot of the SQL code and the execution result:
11. For each song in the songs table, update the value of artist_id to the id...
Hi i need Help. i use MYSQL command line. THE QUESTION ARE BELOW please check the answer before you submit because sometimes query gives error thank you For Full database of SQL you can DOWNLOAD from this link: https://drive.google.com/file/d/1xh1TcBfMtvKoxvJr7Csgnts68fF53Q1t/view?usp=sharing ------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- What are the total sales for each year. Note that you will need to use the YEAR function. Order by year with the newest year first. ------------------------------------------------------- How many employees have no customers? ------------------------------------------------------------------ List the total sales for...