Difference between revisions of "Concatenate Columns"

From SQLZOO
Jump to: navigation, search
Line 7: Line 7:
 
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'>DROP TABLE bbc;
 +
</source>
 +
<source lang=sql class='setup'>CREATE TABLE bbc (name VARCHAR(10), region VARCHAR(10));
 
INSERT INTO bbc VALUES ('Poland', 'Europe');
 
INSERT INTO bbc VALUES ('Poland', 'Europe');
 
INSERT INTO bbc VALUES ('Japan', 'Asia');
 
INSERT INTO bbc VALUES ('Japan', 'Asia');

Revision as of 13:48, 11 July 2012

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

schema:scott

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.

DROP TABLE bbc;
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