长风秋雁
我们需要对原始查询使用CONCAT_WS(),但也要了解CONCAT()。那么为什么我们使用CONCAT_WS()呢?CONCAT()和CONCAT_WS()函数都用于连接两个或多个字符串,但是它们之间的基本区别在于CONCAT_WS()函数可以与字符串之间的分隔符一起进行连接,而在CONCAT()函数中则没有概念分隔符的例子:mysql> Select CONCAT('Akash','is','a','good','developer') AS 'Example of CONCAT()';+---------------------+| Example of CONCAT() |+---------------------+| Akashisagooddeveloper |+---------------------+1 row in set (0.00 sec)mysql> Select CONCAT_WS(' ','Akash','is','a','good','developer') AS 'Example of CONCAT_WS()';+------------------------+| Example of CONCAT_WS() |+------------------------+| Akash is a good developer |+------------------------+1 row in set (0.00 sec)$resident = Resident::where(DB::raw('CONCAT_WS(" ", resident_fname, resident_mi, resident_lname)'), 'like', $request->input('reservation_name'))->first();