Skip to Main Content
SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, Second Edition
book

SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, Second Edition

by John L. Viescas, Michael J. Hernandez
September 2007
Intermediate to advanced content levelIntermediate to advanced
672 pages
13h 23m
English
Addison-Wesley Professional
Content preview from SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, Second Edition

Writing Requests with UNION

In the previous chapters on INNER JOIN and OUTER JOIN, we studied how to construct a SELECT statement using the SELECT, FROM, and WHERE clauses. The focus of those two chapters was on constructing complex JOINs within the FROM clause. To construct a UNION, you now have to graduate to a SELECT expression that links two or more SELECT statements with the UNION operator. Each SELECT statement can have as simple or complex a FROM clause as you need to get the job done.

Using Simple SELECT Statements

Let’s start simply by creating a UNION of two simple SELECT statements that use a single table in the FROM clause. Figure 10-4 shows the syntax diagram for a UNION of two simple SELECT statements.

Figure 10-4. Using a UNION ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SQL Queries for Mere Mortals®: A Hands-On Guide to Data Manipulation in SQL, Third Edition

SQL Queries for Mere Mortals®: A Hands-On Guide to Data Manipulation in SQL, Third Edition

John Viescas, Michael J. Hernandez
Effective SQL: 61 Specific Ways to Write Better SQL, First Edition

Effective SQL: 61 Specific Ways to Write Better SQL, First Edition

John L. Viescas, Douglas J. Steele, Ben G. Clothier
SQL for Data Analytics

SQL for Data Analytics

Upom Malik, Matt Goldwasser, Benjamin Johnston

Publisher Resources

ISBN: 9780321444431Purchase book