I have a small problem with an SQL query. Maybe I just couldn’t wake up yet, having my 2nd coffee but still seems like my brain can’t work or figure out yet and it is already making my day (morning) really bad.
What I want to do is to count records from 2 tables with duplicates as 1 record. Lets say;
1. members table
2. subscriptions table.
I would like to find how many members has an active subscription.
SELECT COUNT(*) FROM members as main
INNER JOIN subscriptions as sub ON sub.member_id = main.id
WHERE
sub.status = '2' AND sub.active = '1'
GROUP BY main.id
Obviously that’s not it. A member could have more than 1 active subscription so I would like to count that member as 1 subscriber (no matter how many active subscription a member has).
I’m planing to create a new table to members subscriptions but that’s just going to have a table which I might not really need at this point.
Any suggestions would be much appreciated.
This should do the trick: