Difference between revisions of "Concatenate Columns"

From SQLZOO
Jump to: navigation, search
Line 2: Line 2:
 
<div class='ht'>
 
<div class='ht'>
 
<div>
 
<div>
You can put two or more strings together using the concatentate operator.
+
You can put two or more strings together using the concatenate operator.
 
The SQL standard says you should use || but there are many differences
 
The SQL standard says you should use || but there are many differences
 
between the main vendors.
 
between the main vendors.
Line 22: Line 22:
 
<div class="ecomm e-sqlserver" style="display: none">Use +</div>
 
<div class="ecomm e-sqlserver" style="display: none">Use +</div>
 
<div class="ecomm e-mysql" style="display: none">Use CONCAT</div>
 
<div class="ecomm e-mysql" style="display: none">Use CONCAT</div>
 
 
</div>
 
</div>

Revision as of 09:25, 11 July 2012

You can put two or more strings together using the concatenate operator.

You can put two or more strings together using the concatenate operator. The SQL standard says you should use || but there are many differences between the main vendors.

CREATE TABLE bbc (name VARCHAR(10), region VARCHAR(10));
INSERT INTO bbc VALUES ('Poland', 'Europe');
INSERT INTO bbc VALUES ('Japan', 'Asia');
SELECT region & name
  FROM bbc
SELECT region + name
  FROM bbc
SELECT CONCAT(region, name)
  FROM bbc
SELECT region || name
  FROM bbc
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense