CREATE DATABASE record_company;
USE record_company;
CREATE TABLE bands (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE albums (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
release_year INT,
band_id INT NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (band_id) REFERENCES bands(id)
);
Insert records/data
INSERT INTO bands(id,name) VALUES (1,'Seventh Wonder');
Join
-- Get all Bands that have Albums
SELECT DISTINCT bands.name FROM bands
JOIN albums ON bands.id = albums.band_id;
Delete
DELETE FROM albums
WHERE id = 19;
Average
SELECT AVG(length) as 'Average Song Duration'
FROM songs;