我正在尝试生成一个查询,该查询从用户表中选择所有名字的姓氏的任何组合与特定的搜索词匹配
$select = $select->where('last_name LIKE ?', '%'.$term.'%')->orWhere('first_name LIKE ?', '%'.$term.'%')
->orWhere("CONCAT(first_name,' ', last_name) LIKE ?", '%'.$term.'%')
->orWhere("CONCAT(last_name,' ', first_name) LIKE ?", '%'.$term.'%');
还有一个条件也必须满足,它在另一个 where 子句中指定
$select = $select->where("deleted = 0 AND scholar = 0");
生成以下 SQL 语句
SELECT `user`.* FROM `user` WHERE (last_name LIKE '%frank%') OR (first_name LIKE '%frank%') OR (CONCAT(first_name,' ', last_name) LIKE '%frank%') OR (CONCAT(last_name,' ', first_name) LIKE '%frank%') AND (deleted = 0 AND scholar = 0) ORDER BY `date_created` desc LIMIT 25
这不会返回所需的结果,因为我得到了学者 = 1 的行;
我认为查询应该是
SELECT `user`.* FROM `user` WHERE ((last_name LIKE '%frank%') OR (first_name LIKE '%frank%') OR (CONCAT(first_name,' ', last_name) LIKE '%frank%') OR (CONCAT(last_name,' ', first_name) LIKE '%frank%')) AND (deleted = 0 AND scholar = 0) ORDER BY `date_created` DESC LIMIT 25
使用 $select 对象实现此目的的正确语法是什么。