SQL CONCAT() Function - The Coding Shala

Home >> Learn SQL >> SQL CONCAT() function

SQL CONCAT() Function

The SQL CONCAT() is used to concatenate two strings. In MySQL, we use '||'.
SQL CONCAT() Function - The Coding Shala

SQL CONCAT() Syntax

The basic syntax of SQL CONCAT() is as follows - 

 SELECT CONCAT(column_name1, column_name2, ..)  
 FROM table_name  

NOTE: In MySQL, we use '||' instead of CONCAT().

The following 'emp' table is used for the example - 

emp_id     emp_name     city     dept_no     salary  
 1          Akshay        Pune      101       50000  
 3          Nikhil        Pune      101       51000  
 5          Mohit         Delhi     103       40000  
 6          Shubham       Surat     105       42000  
 7          Akash         Mumbai    106       45000 

SQL CONCAT() Example

The following SQL query will concatenate two columns using || in MySQL -  

 SQL >> select emp_name || ' is from ' || city as 'Emp Detail'  
        from emp;  
 
Output >>   
 Emp Detail  
 Akshay is from Pune  
 Nikhil is from Pune  
 Mohit is from Delhi  
 Shubham is from Surat  
 Akash is from Mumbai 



Other Posts You May Like
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Shell Script to find sum, product and average of given numbers - The Coding Shala

New Year Chaos Solution - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Java Method Overloading - The Coding Shala

Java Program to Convert Binary to Decimal - The Coding Shala