将查询从不存在的地方转换为左连接

Converting query from where not exist to Left Join

我正在使用 laravel 5.2,我在转换此查询时遇到问题

 DB::select('SELECT m.*
            FROM member_table AS m
            JOIN treepaths AS t ON m.membershipid = t.descendant
            WHERE m.stage >=' . $usermatrixtype . '
            AND t.ancestor =' . "'" . $firstrightchildmembershipid . "'" . '
            AND NOT EXISTS (
            select user_id from matrix_users AS mr WHERE mr.user_id=m.membershipid AND matrix_id=' . $getusermatrix . '
            ) LIMIT ' . $results
);

这是我试过的方法

 DB::select('SELECT m.membershipid
            FROM member_table AS m
            JOIN treepaths AS t ON m.membershipid = t.descendant
            WHERE m.stage >=' . $usermatrixtype . '
            AND t.ancestor =' . "'" . $firstleftchildmembershipid . "'" .'
            LEFT OUTER JOIN matrix_users AS mu ON mu.user_id =m.membershipid WHERE
           matrix_id=' . $getusermatrix . ' AND
            mu.userid IS NULL
             LIMIT ' . $results);

它returns没什么

试试这个:

 DB::select('SELECT m.membershipid
            FROM member_table AS m
            JOIN treepaths AS t ON m.membershipid = t.descendant
            LEFT JOIN matrix_users AS mu ON mu.user_id =m.membershipid AND  matrix_id=' . $getusermatrix . '
            WHERE  mu.userid IS NULL AND m.stage >=' . $usermatrixtype . '
            AND t.ancestor =' . "'" . $firstleftchildmembershipid . "'" .'

             LIMIT ' . $results);