Wednesday, 2 October 2013

Count matching accross two tables

Count matching accross two tables

I have two tables. The 'submissions' table holds details about the submission
The 'judging' table holds other details.
The judging table has a 'rel_id' field which links the two tables
together. (Holds the row ID number from the submissions table that it has
a relationship with).
In the judging table there are multiple rows with the same rel_id.
I want to count how many single rows there are in the judging table that
meets the criteria below, and only 1 of each rel_id.
This is as far as I have managed to get, but I can't get it working.
SELECT COUNT(*) AS count_result
FROM exp_judging AS jud
LEFT JOIN exp_submissions AS sub ON jud.rel_id = sub.id
WHERE jud.pre = 1
AND sub.member_group = $member_group
GROUP BY jud.rel_id
Any help would be great.

No comments:

Post a Comment