SQL Concatenate, SQL Tutorial, Global Guide Line Technology.
Forum | Blog |


Basic SQL Guide.           
SQL Introduction.               
 What is Table?                  
 SQL Create Table.            
 SQL Insert Statement.      
 SQL Select Keyword.        
 SQL Order by clause.        
 SQL Count Statement.      
 SQL Group By Clause.      
 SQL Having Clause.          
 SQL Alias Tables.             
 SQL Join Tables.              
 SQL Outer Join.               
 SQL Update Statement.   
 SQL Delete Statement.    
 SQL Distinct Keyword.      
 SQL Where Keyword.       
 SQL And Or Keyword.      
 SQL In Keyword.              
 SQL Between Keyword.   
 SQL Like Keyword.          
 SQL Functions.                
 SQL Concatenate.
 SQL Substrings.               
 SQL Trim Function.         
 SQL Constraints.              
 SQL Primary Key.            
 SQL Foreign Key.            
 SQL Create Views.           
 SQL Create Index.           
 SQL Alter Table.             
 SQL Drop Table.             
 SQL Truncate Table.      
 SQL Summary.                

SQL Tutorial >> SQL Concatenate.

     Back             Next     

SQL Tutorial will explain us that sometimes it is necessary to combine together (concatenate) the results from several different fields from one or more database tables. Each database provides a way to do this but each database follows the different way from others.

Syntax for SQL Concatenate

MySQL:      CONCAT() 

Oracle:     CONCAT(), ||

SQL Server: +

The syntax for CONCAT() Function is as follows:

CONCAT(str1, str2, str3, ...): Concatenate str1, str2, str3, and any other strings together. Please note the Oracle database CONCAT() function only allows two arguments -- only two strings can be put together at a time using this function. However, it is possible to concatenate more than two strings at a time in database Oracle using '||' sign.

Let's look at some SQL Concatenate examples. Assume we have the following table:

Table: Employees
FirstName LastName Email DOB Phone
Austin Hennery austin.it@gamail.com 24/11/1978 446 102-2222
Creston Narvon narvon_crest@hotmail.com 22/04/1976 443 325-4545
Kate Bladen kbladen@usa.net 01/05/1980 326 503-3232
Angela Julie julieee@yahoo.co.uk 11/12/1977 326 323-8888
Bobbi Ferguson bobi123@kiwibox.com 10/02/1970 506 252-9875
Cute Alfa cafa@gmail.com 19/05/1972 506 272-4566

SQL Concatenate Examples in Oracle, MySQL and SQL Server

Example 1:

In MySQL/Oracle Concatenate Example.

SELECT CONCAT(FirstName,LastName) "Employee First & Last Name" FROM Employees

Results of Concatenate Example using Oracle or MySQL databases.

Employee First & Last Name

Example 2:

Oracle Concatenate more then two columns Example.

SELECT FirstName || ' ' || LastName || ', contact number is ' || Phone FROM Employees

Results of SQL Concatenate more then two columns Example in Oracle

Employee First & Last Name with Phone Number
Austin Hennery, contact number is 446 102-2222
Angela Julie, contact number is 326 323-8888
Bobbi Ferguson, contact number is 506 252-9875
Creston Narvon, contact number is 443 325-4545
Cute Alfa, contact number is 506 272-4566
Kate Bladen, contact number is 326 503-3232

Example 3:

SQL Concatenate Example in SQL Server.

SELECT FirstName + ' ' + LastName FROM Employees

Results of SQL Concatenate Example in SQL Server.

Employee First & Last Name
Austin Hennery
Angela Julie
Bobbi Ferguson
Creston Narvon
Cute Alfa
Kate Bladen

     Back             Next     

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2022 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 412 visitors are online now