Search
 
SCRIPT & CODE EXAMPLE
 

SQL

concat in laravel 8


    $users = DB::table('users')->select("*", DB::raw("CONCAT(users.first_name,' ',users.last_name) AS full_name"))
        ->get();
Comment

concat using laravel

//must have
use IlluminateSupportFacadesDB;

Model::select(DB::Raw("CONCAT(profiles.first_name, ' ', profiles.last_name) AS name"))->get();

//concat other table data and display as one line with ',' as a delimiter
//DB::Raw("(SELECT GROUP_CONCAT(a.contact_number) FROM contacts as a JOIN users as b ON a.user_id = b.user_id WHERE a.user_id = users.user_id) AS contact")
//expected output would be 09123456789,09876543210,09000000000
Comment

how to use CONCAT in LARAVEL

public function scopeFindUserByName($query,$name) {
    // Concat the name columns and then apply search query on full name
    $query->where(DB::raw(
            // REPLACE will remove the double white space with single (As defined)
            "REPLACE(
                /* CONCAT will concat the columns with defined separator */
                CONCAT(
                    /* COALESCE operator will handle NUll values as defined value. */
                    COALESCE(name_first,''),' ',
                    COALESCE(name_middle,''),' ',
                    COALESCE(name_last,'')
                ),
            '  ',' ')"
        ),
    'like', '%' . $name . '%');
}
Comment

PREVIOUS NEXT
Code Example
Sql :: database disk image is malformed sqlite fix ubuntu 
Sql :: postgresql export database 
Sql :: How do I add a user to a postgres database? cli 
Sql :: alter column to null 
Sql :: Get the Db column names from a SqlDataReader 
Sql :: savepoint in sql 
Sql :: plsql print 
Sql :: Get monday of week date is in SQL 
Sql :: cursor.execute in python sqlite3 
Sql :: delete join select from one table based on multiple values 
Sql :: spring where to put the data sql 
Sql :: mysql query single row 
Sql :: select new table sql 
Sql :: get number of table colums in sql query 
Sql :: postgres show databases 
Sql :: mysql date range 
Sql :: alter table add multiple columns postgresql 
Sql :: postgre describe table 
Sql :: update with select postgresql 
Sql :: mariadb hours between two dates 
Sql :: sqlalchemy return id after insert 
Sql :: SQL Error 1040 : Too many connections 
Sql :: how to delete the rows with null values in mysql 
Sql :: SQL ORDER BY DESC (Descending Order) 
Sql :: postgresql function 
Sql :: snowflake drop column 
Sql :: activate log mariadb 
Sql :: flask sqlalchemy update row 
Sql :: sql select rows with different values in one column 
Sql :: how to change column name in mysql 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =