Home Tutorials IT Jobs Source Codes Certifications Discussion Forum
  SQL Tutorials
SQL SELECT
SQL DISTINCT
SQL WHERE
SQL AND OR
SQL IN
SQL BETWEEN
SQL LIKE
SQL ORDER BY
SQL FUNCTIONS
SQL COUNT
SQL GROUP BY
SQL HAVING
SQL ALIAS
SQL JOIN
SQL OUTER JOIN
SQL CONCATENATE
SQL SUBSTRING
SQL TRIM
SQL CREATE TABLE
SQL CONSTRAINT
SQL PRIMARY KEY
SQL FOREIGN KEY
SQL CREATE VIEW
SQL CREATE INDEX
SQL ALTER TABLE
SQL DROP TABLE
SQL TRUNCATE TABLE
SQL INSERT INTO
SQL DELETE FROM
   IT Jobs
Software Jobs
Networking Jobs
   Model Question Papers
BE Computer Science
MCA
BCA
Others
 
   

SQL CONCATENATE

Sometimes it is necessary to combine together (concatenate) the results from several different fields. Each database provides a way to do this:

MySQL: CONCAT() 
Oracle: CONCAT(), || 
SQL Server: + 
The syntax for CONCAT() is as follows:

CONCAT(str1, str2, str3, ...): Concatenate str1, str2, str3, and any other strings together. Please note the Oracle 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 Oracle using '||'.

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

Table Geography

region_name store_name
East Boston
East New York
West Los Angeles
West San Diego

Example 1:

MySQL/Oracle: 
SELECT CONCAT(region_name,store_name) FROM Geography 
WHERE store_name = 'Boston';

Result:

'EastBoston'

Example 2:

Oracle: 
SELECT region_name || ' ' || store_name FROM Geography 
WHERE store_name = 'Boston';

Result:

'East Boston'

Example 3:

SQL Server: 
SELECT region_name + ' ' + store_name FROM Geography 
WHERE store_name = 'Boston';

Result:

'East Boston'

 

<< Previous | Next >>

 
Home  |  About us  | Privacy  |  Disclaimer  |  Contact us |  Advertise with us | Our Link Partners
All Rights Reserved 2009, CodeTeller.com