Concatenation is the process of combining data strings.
For example, the concatenation of 'John', ' ', 'W', '. ' and 'Smith' is
'John W. Smith'
Also, the concatenation of '212', '-', '555', '-' and '1234' is
'212-555-1234'
Concatenation can result in more readable output while maintaining data in separate columns for greater flexibility.
The means of achieving concatenation differs by database type. for example:
More than 2 strings can be combined through concatenation. Numbers must be converted to strings before concatenation.
SQL Concatenation Syntax
SQL Concatenation Example
The following example concatenates the column branch_name with column region_name along with spaces and parens for readability.
Here are the contents of the tables:
Table: REGION
region_nbr | region_name |
100 | East Region |
200 | Central Region |
300 | Virtual Region |
400 | West Region |
Table: BRANCH
branch_nbr | branch_name | region_nbr | employee_count |
108 | New York | 100 | 10 |
110 | Boston | 100 | 6 |
212 | Chicago | 200 | 5 |
404 | San Diego | 400 | 6 |
415 | San Jose | 400 | 3 |
This SQL Statement with concatenation is executed:
Here is the result.
branch_name (region_name) |
New York (East Region) |
Boston (East Region) |
Chicago (Central Region) |
San Diego (West Region) |
San Jose (West Region) |
Advertisements:
Infogoal.com is organized to help you gain mastery.
Examples may be simplified to facilitate learning.
Content is reviewed for errors but is not warranted to be 100% correct.
In order to use this site, you must read and agree to the
terms of use, privacy policy and cookie policy.
Copyright 2006-2020 by Infogoal, LLC. All Rights Reserved.