Click here to navigate the course.

Drag the edges to resize the window.

In Projects, you can keep track of your progress as you go throught the tasks. Check each item as you complete it!

Code Editor

Query Results

Run a query to see results.

Database Schema

Schema undefined.
Learn
Multiple Tables

Union

Sometimes we want to stack one dataset on top of the other.

UNION allows us to do that.

Suppose we have two tables and they have the same columns:

table1

name email
Sonny sonny@foobar.com
Eric posture@boy.net


table2

name email
Chloe wallflower1991@gsnail.com
Ned sk8terboi@lotmail.com


If we combine these two with UNION:

SELECT * FROM table1 UNION SELECT * FROM table2;


The result would be:

name email
Sonny sonny@foobar.com
Eric posture@boy.net
Chloe wallflower1991@gsnail.com
Ned sk8terboi@lotmail.com


SQL has strict rules for appending data:

  • Tables must have the same # of columns.
  • The columns must have the same data types in the same order as the first table.
Report a Bug
If you see a bug or any other issue with this page, please report it here.