Difference between revisions of "UNION"

From SQLZOO
Jump to: navigation, search
(Blanked the page)
Line 1: Line 1:
 +
Make union between different tables to build one single view or results?
 +
<div class='ht'>
 +
<div class=params>schema:gisq</div>
 +
<div>
 +
List a number of SELECT statements separated by the UNION key word. Be sure that you have the same number of columns in each of the SELECT statements.
 +
</div>
 +
<source lang=sql class='tidy'></source>
 +
<source lang=sql class='setup'></source>
  
 +
<source lang='sql' class='def e-access'>
 +
SELECT name FROM bbc WHERE name LIKE 'Z%'
 +
UNION
 +
SELECT name FROM actor WHERE name LIKE 'Z%'
 +
</source>
 +
<source lang='sql' class='def e-sqlserver'>
 +
SELECT name FROM bbc WHERE name LIKE 'Z%'
 +
UNION
 +
SELECT name FROM actor WHERE name LIKE 'Z%'
 +
</source>
 +
<source lang='sql' class='def e-mysql'>
 +
SELECT name FROM bbc WHERE name LIKE 'Z%'
 +
UNION
 +
SELECT name FROM actor WHERE name LIKE 'Z%'
 +
</source>
 +
<source lang='sql' class='def'>
 +
SELECT name FROM bbc WHERE name LIKE 'Z%'
 +
UNION
 +
SELECT name FROM actor WHERE name LIKE 'Z%'
 +
</source>
 +
<div class="ecomm e-mysql">UNION will be available from version 4</div>
 +
</div>
 +
 +
{{SELECT Ref}}

Revision as of 11:45, 10 September 2012

Make union between different tables to build one single view or results?

schema:gisq

List a number of SELECT statements separated by the UNION key word. Be sure that you have the same number of columns in each of the SELECT statements.

 
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
UNION
SELECT name FROM actor WHERE name LIKE 'Z%'
SELECT name FROM bbc WHERE name LIKE 'Z%'
UNION
SELECT name FROM actor WHERE name LIKE 'Z%'
SELECT name FROM bbc WHERE name LIKE 'Z%'
UNION
SELECT name FROM actor WHERE name LIKE 'Z%'
SELECT name FROM bbc WHERE name LIKE 'Z%'
UNION
SELECT name FROM actor WHERE name LIKE 'Z%'
UNION will be available from version 4
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense