开发者

Compare value with concatenated fields in where clause

开发者 https://www.devze.com 2023-02-13 01:27 出处:网络
Say开发者_StackOverflow中文版 I want to search for a user, \'Richard Best\'. Is it possible to compare the full name is concatenated first name and last name? I do not havea full name field.

Say开发者_StackOverflow中文版 I want to search for a user, 'Richard Best'. Is it possible to compare the full name is concatenated first name and last name? I do not have a full name field.

select * from users where last_name + ' ' + first_name like '%richa%'

I am using Mysql


These are equivalent:

select * from users where concat(last_name,' ',first_name) like '%richa%'

select * from users where concat_ws(' ',last_name,first_name) like '%richa%'

This might also work:

select * from users where last_name like '%richa%' or first_name like '%richa%'


Take a look at this thread.

Using mysql concat() in WHERE clause?


select * from users where (first_name + ' ' + last_name) like '%richa%'


In laravel Eloquent you can use whereRaw("concat(first_name,' ',last_name) LIKE %$search%")

0

精彩评论

暂无评论...
验证码 换一张
取 消