Goal:
Need results for channels that are active (channels.active=1) but have 0 active items.
There are items and they belong in channel. items can have multiple channels.
There are 3 tables:
channelsitemsitems_channels
The items_channel maps items to channels. Example row:
id item channel
1 23 47
So far I just have this to get active channels:
SELECT * FROM channels WHERE channels.active = 1
I’m having trouble grasping the part where I only join the channels that have 0 active items – do I need a subquery or a HAVING clause that has a COUNT somewhere?
Also, channels.active is for active channels, and items.active is for active items.
This should work for you:
Working sqlfiddle here.