MYSQL在我的查询中忽略AND子句

时间:2016-09-18 10:11:07

标签: php mysql

我有以下查询,AND状态= 1被忽略,我得到所有状态而不是只有等于1.我的错误在哪里?

$query = "
                SELECT state, id, variable, name, {$columns->specific}, {$columns->allExcept}, {$columns->specificExclude}, {$columns->relationAllExcept}, repeatable

                FROM #__epc_fieldsgroups
                WHERE FIND_IN_SET({$relationRecordId}, {$columns->specific})

                OR {$columns->allExcept} != 0
                AND FIND_IN_SET({$relationRecordId}, {$columns->allExcept}) = 0

                AND state = 1
                ORDER BY ordering
             ";

1 个答案:

答案 0 :(得分:0)

您需要使用括号

定义AND的开始和结束
$query = "
                SELECT state, id, variable, name, {$columns->specific}, {$columns->allExcept}, {$columns->specificExclude}, {$columns->relationAllExcept}, repeatable

                FROM #__epc_fieldsgroups
                WHERE FIND_IN_SET({$relationRecordId}, {$columns->specific})

                OR {$columns->allExcept} != 0
                AND {FIND_IN_SET({$relationRecordId}, {$columns->allExcept}) = 0}

                AND {state = 1}
                ORDER BY ordering
             ";