Using if in where clause with datatable editor

Using if in where clause with datatable editor

kharismaticskharismatics Posts: 6Questions: 2Answers: 0

How can i use if condition with WHERE CLAUSE of datatable editor

here is the query example

SELECT
*
FROM
tablename
WHERE IF(category=1, rule = 1, rule = 2)

This question has an accepted answers - jump to answer

Answers

  • kharismaticskharismatics Posts: 6Questions: 2Answers: 0

    ->where( function ( $q ) {
    $q
    ->where( "IF(category=1,rule = 1,rule = 2)", "if(1=1,1,0)", "=", false );
    })

    im using this right now but i think there is a better way :neutral:

  • allanallan Posts: 62,333Questions: 1Answers: 10,228 Site admin
    Answer ✓

    I think the only better way would be to use a VIEW. There aren't any methods in the database abstraction to apply if conditions in the SQL.

    Allan

  • kharismaticskharismatics Posts: 6Questions: 2Answers: 0

    thanks @allan for the suggestion :blush:

This discussion has been closed.