I have 3 tables as shown below:
subscription_plans

subscribed_videos

subscription_groups

I want to find the plans corresponding to the selected video (table subscription_plans). Table subscription_groups contains the plan-plan mapping ie, a plan can be part of another plan. For example, Plan A, Plan B and Plan C. Plan A contains both Plan B an Plan C and video with id 5 is part of Plan B (table subscribed_videos) , then the query for finding the plans corresponding to video 5 should return Plan A along with Plan B. Also the records should be distinct.
I tried with the following query. But if I am adding a plan which don't have an entry in subscription_groups, then that record is not returning with this query.
$videoid=$_POST['videoid'];
echo "select sv.plan_id,sg.plan_id,sp.id,sp.plan,sp.days_limit,sp.rate from subscribed_videos as sv
LEFT JOIN subscription_groups as sg ON sv.plan_id=sg.assosiated_plan_id INNER JOIN
subscription_plans as sp ON sv.plan_id=sp.id where sg.assosiated_plan_id=sv.plan_id and sv.videoid=$videoid
and sg.assosiated_plan_id=sp.id";
Can anyone help me to find the appropriate query for this ? Thanks in advance.