Hi guys,
Just need to get my head around something, hopefully somebody can point me in the right direction.
If I am creating a database that stores song information, whereby each song would have multiple genres, would I be right in assuming that my database tables should be setup in a similar fashion to this:
Table: Song
Columns:-
ID
TITLE
LENGTH
Table: Genre
Columns:-
ID
SID (Song.ID)
GENRE
This allows me to then put in as many genres as possible for each song. I can search for specific genres or multiple genres and it returns the correct result.
So, this query will return a single result per song if it contains the genre Pop or Rock, which is exactly what I want.
However, my problem comes about when I try to add a third table. I now want each song to be searchable by instruments used. So, I create a new table similar to the genre.
Table: Instrument
Columns:-
ID
SID (Song.ID)
INSTRUMENT
Now the bit I am stuck on is this next bit, lets say I now want to return all results that have the genre of 'Pop' but also use the instrument 'Guitar'. What sort of query should I be using?
Any help greatly appreciated, and if my database design is completely incorrect please let me know what I can do to fix it!
Many thanks.
Just need to get my head around something, hopefully somebody can point me in the right direction.
If I am creating a database that stores song information, whereby each song would have multiple genres, would I be right in assuming that my database tables should be setup in a similar fashion to this:
Table: Song
Columns:-
ID
TITLE
LENGTH
Table: Genre
Columns:-
ID
SID (Song.ID)
GENRE
This allows me to then put in as many genres as possible for each song. I can search for specific genres or multiple genres and it returns the correct result.
PHP:
$sql="SELECT DISTINCT genre.SID, song.Title, songs.ID, songs.Length
FROM genre
LEFT JOIN song ON genre.SID = song.ID
WHERE genre = 'Rock'
OR genre = 'Pop'";
So, this query will return a single result per song if it contains the genre Pop or Rock, which is exactly what I want.
However, my problem comes about when I try to add a third table. I now want each song to be searchable by instruments used. So, I create a new table similar to the genre.
Table: Instrument
Columns:-
ID
SID (Song.ID)
INSTRUMENT
Now the bit I am stuck on is this next bit, lets say I now want to return all results that have the genre of 'Pop' but also use the instrument 'Guitar'. What sort of query should I be using?
Any help greatly appreciated, and if my database design is completely incorrect please let me know what I can do to fix it!
Many thanks.