swimmingpoole swimmingpoole - 2 months ago 6
MySQL Question

Need help spotting an SQL syntax error in a small query

I'm getting an SQL syntax error "around line 5" of the following code..

SELECT artists.name, albums.title, genres.genre
FROM artist_album
JOIN artists ON artist_album.artist_id = artists.id
JOIN albums ON artist_album.album_id = albums.album_id
FROM album_genre
JOIN genres ON album_genre.genre_id = genres.genre_id
WHERE genres.genre = 'Pop' OR genres.genre = 'Rock'


What I am trying to find is all artists in the database who released a ‘Rock’ or a ‘Pop’ album. The query should return artist name, album title, and album genre..

My tables are:

albums
album_id
released
title

artist
id
name

genres
genre_id
genre

album_genre
album_id
genre_id

artist_album
album_id
artist_id


I am very new to SQL, so i'm sure what I am doing wrong is something I am unaware of.. but after digging around the internet for a bit I cannot see what I may syntactically be doing wrong.

Any help/suggestions would be much appreciated, thanks!

Answer

looks like it should be

JOIN album_genre ON album_genre.album_id = albums.album_id

instead of

FROM album_genre
Comments