Where clause in MJoin

Where clause in MJoin

kea0811kea0811 Posts: 10Questions: 2Answers: 1


Is it possible to include where clause in MJoin? The where clause will involve both tables.


  • allanallan Posts: 46,589Questions: 1Answers: 6,505 Site admin

    You can use a where condition on the target table, but you cannot currently have it cross between both tables I'm afraid. The reason for that is that it is actually two different SQL queries - one to get the host table's data and another to get the joined table's data. The library then combines them in PHP.


  • rw152rw152 Posts: 38Questions: 12Answers: 1
    edited August 2017

    Howdy! I just stumbled upon this issue myself. This is how I got around it:

    $editor->where( function ( $q ) {
        $q->where( 'accessLevel', '(SELECT id FROM access WHERE level LIKE "%admin%")', 'IN', false );
    } )

    The using the closure where function on the "parent" table allowed me to effectively simulate a where clause on the Mjoined table. Hope this helps anyone else stuck in the same situation!

    Reference: https://editor.datatables.net/manual/php/conditions#Sub-selects

Sign In or Register to comment.