In a table where there is a subscriber_id
and a letter_id
, a subscriber might be subscribed to more than one letter. I want to unsubscribe people from a certain letter if they are subscribed to ANY other letter. I need help building a query. I've seen what I might call nested queries before but I'm not experienced in writing them.
I could probably do this in PHP by first querying like:
SELECT subscriber_id FROM subscriptions WHERE letter_id=3
then run a foreach on the result and delete where a subscriber_id has more than one match, but I'd bet MySQL can do this a lot faster if I only knew how.
I tried to write pseudo code here, but I get hung up even on that.
In case it helps, each row also has its own id.