开发者

Compare value with concatenated fields in where clause

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜