I have 4 tables for a music voting site.
I want to count how many votes each song has for a particular chart (id = 4)
Here is how the vote table looks when people vote for a song (id = 1) to chart id (4)
id | song_id_fk | chart_id_fk |
1 | 1 | 4 |
2 | 1 | 4 |
Hopefully u understand. Please help. If I pass 'WHERE chart_id_fk = 4'
, I want to get a count of 2 for song_id_fk = 1
.
I guess you are looking for something like
select count(*) as vote_count, song_id_fk, chart_id_fk from votes group by song_id_fk, chart_id_fk