How to concatenate columns in a Postgres SELECT?

后端 未结 8 1696
醉酒成梦
醉酒成梦 2020-11-27 13:31

I have two string columns a and b in a table foo.

select a, b from foo returns values a and b<

8条回答
  •  情话喂你
    2020-11-27 13:44

    PHP's Laravel framework, I am using search first_name, last_name Fields consider like Full Name Search

    Using || symbol Or concat_ws(), concat() methods

    $names = str_replace(" ", "", $searchKey);                               
    $customers = Customer::where('organization_id',$this->user->organization_id)
                 ->where(function ($q) use ($searchKey, $names) {
                     $q->orWhere('phone_number', 'ilike', "%{$searchKey}%"); 
                     $q->orWhere('email', 'ilike', "%{$searchKey}%");
                     $q->orWhereRaw('(first_name || last_name) LIKE ? ', '%' . $names. '%');
        })->orderBy('created_at','desc')->paginate(20);
    

    This worked charm!!!

提交回复
热议问题