Union

From SQLZOO
Revision as of 16:11, 10 July 2012 by Marek (Talk | contribs)

Jump to: navigation, search

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

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.

CREATE TABLE bbc (name VARCHAR(10), region VARCHAR(10));
INSERT INTO bbc VALUES ('Poland', 'Europe');
INSERT INTO bbc VALUES ('Japan', 'Asia');
SELECT name FROM actor WHERE name LIKE 'Z%'
UNION
SELECT name FROM bbc WHERE name LIKE 'Z%'
SELECT name FROM actor WHERE name LIKE 'Z%'
UNION
SELECT name FROM bbc WHERE name LIKE 'Z%'
SELECT name FROM actor WHERE name LIKE 'Z%'
UNION
SELECT name FROM bbc WHERE name LIKE 'Z%'
SELECT name FROM actor WHERE name LIKE 'Z%'
UNION
SELECT name FROM bbc WHERE name LIKE 'Z%'
UNION will be available from version 4
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense