Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Subquery not returning expected results

Codes here !

Moderators: macek, egami, gesf

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
New php-forum User
New php-forum User
Posts: 1
Joined: Sat May 03, 2014 1:23 am

Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.