Difference between revisions of "Concatenate Columns"

From SQLZOO
Jump to: navigation, search
 
(9 intermediate revisions by one user not shown)
Line 1: Line 1:
 
You can put two or more strings together using the concatenate operator.
 
You can put two or more strings together using the concatenate operator.
 
<div class='ht'>
 
<div class='ht'>
 +
<div class=params>schema:gisq</div>
 
<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.
 
</div>
 
</div>
<source lang=sql class='tidy'>CREATE TABLE bbc (name VARCHAR(10), region VARCHAR(10));
+
<source lang=sql class='tidy'></source>
INSERT INTO bbc VALUES ('Poland', 'Europe');
+
<source lang=sql class='setup'></source>
INSERT INTO bbc VALUES ('Japan', 'Asia');
+
</source>
+
 
<source lang='sql' class='def e-access'>SELECT region & name
 
<source lang='sql' class='def e-access'>SELECT region & name
 
   FROM bbc</source>
 
   FROM bbc</source>
Line 20: Line 19:
 
</source>
 
</source>
 
<div class="ecomm e-access" style="display: none">Use ampersand: &</div>
 
<div class="ecomm e-access" style="display: none">Use ampersand: &</div>
<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>
 +
{{SELECT Ref}}

Latest revision as of 13:01, 12 July 2012

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

schema:gisq

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.

 
 
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