Difference between revisions of "Union"

From SQLZOO
Jump to: navigation, search
 
(One intermediate revision by one user not shown)
Line 9: Line 9:
  
 
<source lang='sql' class='def e-access'>
 
<source lang='sql' class='def e-access'>
SELECT name FROM actor WHERE name LIKE 'Z%'
 
UNION
 
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
 +
UNION
 +
SELECT name FROM actor WHERE name LIKE 'Z%'
 
</source>
 
</source>
 
<source lang='sql' class='def e-sqlserver'>
 
<source lang='sql' class='def e-sqlserver'>
SELECT name FROM actor WHERE name LIKE 'Z%'
 
UNION
 
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
 +
UNION
 +
SELECT name FROM actor WHERE name LIKE 'Z%'
 
</source>
 
</source>
 
<source lang='sql' class='def e-mysql'>
 
<source lang='sql' class='def e-mysql'>
SELECT name FROM actor WHERE name LIKE 'Z%'
 
UNION
 
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
 +
UNION
 +
SELECT name FROM actor WHERE name LIKE 'Z%'
 
</source>
 
</source>
 
<source lang='sql' class='def'>
 
<source lang='sql' class='def'>
SELECT name FROM actor WHERE name LIKE 'Z%'
 
UNION
 
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
 
SELECT name FROM bbc WHERE name LIKE 'Z%'
 +
UNION
 +
SELECT name FROM actor WHERE name LIKE 'Z%'
 
</source>
 
</source>
 
<div class="ecomm e-mysql">UNION will be available from version 4</div>
 
<div class="ecomm e-mysql">UNION will be available from version 4</div>

Latest revision as of 14:06, 12 July 2012

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

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