Where clause in MJoin

Where clause in MJoin

kea0811kea0811 Posts: 10Questions: 2Answers: 1

Hello,

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

Replies

  • allanallan Posts: 42,648Questions: 1Answers: 5,493 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.

    Allan

  • rw152rw152 Posts: 25Questions: 8Answers: 1
    edited August 12

    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.