I'm not really sure how to do this - I only posses a limited knowledge of joins in MySQL, and from what I read I don't think they'd be of much use here.
Essentially, I have 2 tables:
images votes
--------------------------- ------------------------------
image_id | name | square_id vote_id | image_id | vote_type
--------------------------- ------------------------------
1 img1 14 1 4 1
2 img2 3 2 17 0
3 img7 72 3 2 1
... ...
n imgn 1478 n n 1
What I'd like to do is get the details of each image and the number of votes cast (plus the vote_type
) on each image where a certain condition is true (such as where each image has a certain square_id
). Executing the first part of this query is easy:
SELECT `image_id`, `name` FROM `images` WHERE `square_id` = :boundParameter;
But, I'm unsure of how to get each vote_id
and vote_type
for each image that meets the original WHERE condition in my query.
How would I accomplish this?