Subquery not returning expected results

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sat May 03, 2014 1:23 am

Subquery not returning expected results

Postby JenzMM11 » Sat May 03, 2014 1:29 am

This is the subquery I have written to get the plans choosed by an user. But this is returning the records in *usersubscription* table even if the user is not subscribed (if there is no records in the table corresponding to the user).

Code: Select all

    $subscribedquery=$this->db->query("select id from usersubscription where plan_id IN
          (SELECT DISTINCT plan_id FROM subscribed_videos sv where sv.videoid = $videoid)
           OR id IN (SELECT DISTINCT assosiated_plan_id
            FROM subscription_groups sg
            JOIN subscribed_videos sv ON sv.plan_id = sg.plan_id
            WHERE sv.videoid = $videoid) and user_id=$userid");

Plz check this fiddle!2/90b2e/1

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 4 guests