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%")
精彩评论