0

My code looks like this

CREATE TABLE Genre (
genreID INT NOT NULL DEFAULT 0,
genreName VARCHAR(20) NULL,
PRIMARY KEY (genreID));


CREATE TABLE Artists (
ArtistID INT NOT NULL DEFAULT 0,
name VARCHAR(45) NULL,
Genre_genreID INT NOT NULL,
PRIMARY KEY (ArtistID),
FOREIGN KEY (Genre_genreID)
REFERENCES Genre(genreID));



CREATE TABLE Albums (
albumsID INT NOT NULL DEFAULT 0,
name VARCHAR(45) NULL,
Artists_ArtistID INT NOT NULL,
PRIMARY KEY (albumsID),
FOREIGN KEY (Artists_ArtistID)
REFERENCES Artists(ArtistID));

CREATE TABLE Songs (
songID INT NOT NULL,
name VARCHAR(45) NULL,
length TIME NULL,
Albums_albumsID INT NOT NULL DEFAULT 0,
PRIMARY KEY (songID),
FOREIGN KEY (Albums_albumsID)
REFERENCES Albums (albumsID));

SELECT Artists.name, Genre.genreName, Songs.name
FROM Songs
INNER JOIN Genre ON Artists.ArtistID=Genre.genreID
INNER JOIN Artists ON Albums.Artists_ArtistID=Artists.ArtistID
INNER JOIN Albums ON Songs.Albums_albumID=Albums.albumsID;

Looking to try and get the name of the artists, genre and song to all match up and display. Yet I get

Unknown column 'Artists.ArtistID' in 'on clause'

Im fairy new to SQL and to INNER JOINS any help and explanations would be great!

2 Answers2

0

Try this

SELECT Artists.name, Genre.genreName, Songs.name
FROM Songs
INNER JOIN Albums ON Songs.Albums_albumID=Albums.albumsID
INNER JOIN Artists ON Albums.Artists_ArtistID=Artists.ArtistID
INNER JOIN Genre ON Artists.ArtistID=Genre.genreID;

check the sequence and occurrence of tables in join

zzlalani
  • 22,960
  • 16
  • 44
  • 73
0

you are mention the Songs table in first row joining. but your joining the table of ON function in last line only like your code, you should try this method:

SELECT 
Artists.name, Genre.genreName, Songs.name
FROM Songs
INNER JOIN Albums 
ON Songs.Albums_albumID=Albums.albumsID
INNER JOIN Artists 
ON Albums.Artists_ArtistID=Artists.ArtistID
INNER JOIN Genre 
ON Artists.ArtistID=Genre.genreID;
jmail
  • 5,944
  • 3
  • 21
  • 35