mysql - WhereNotIn Subquery -


what i'm trying achieve following:

i want check if there record same client_code lower/different campaign id. i'm using sub-query , tried join couldn't logic working

this got now:

    $odb = db::table('campaigns c')         ->select(             'c.id campaign_id',             'cc.id campaign_customer_id'         )         ->join('campaign_customers cc', 'cc.campaign_id', '=', 'c.id')         ->where('c.status', '=', modelcampaign::status_planned)         ->where('c.scheduled', '=', 1)         ->whereraw('c.scheduled_at <= now()')         ->where('cc.status', '=', modelcampaigncustomer::status_invite_email_scheduled)         ->wherenotin('cc.client_code', '=', function ($query){             $query  ->select(db::raw(1))                     ->from('campaign_customers')                     ->whereraw('campaign_id', '!=', 'c.id');         })         ->where('cc.active', '=', 1)     ; 

any tips on how work logic great

you can use ->tosql(); method see sql can refactorize query.


Comments