Skip to Content
Learn SQL in a Month of Lunches
book

Learn SQL in a Month of Lunches

by Jeff Iannucci
February 2025
Beginner content levelBeginner
304 pages
8h 8m
English
Manning Publications
Content preview from Learn SQL in a Month of Lunches

11 Using subqueries and logical operators

In chapter 10, we expanded the scope of our thinking a bit. We saw how to use SQL not only to query tables but also, with the help of set operators such as UNION or INTERSECT, to combine the results of two or more SELECT statements to form a single result set. In this chapter, we’ll build on that knowledge by examining an important method of evaluating the results of multiple SELECT statements in the same query: the subquery.

Subqueries are simply queries nested into another query. We use subqueries when we can’t achieve the desired results from a single SELECT statement, so instead of writing two or more queries, we combine them into a single query. Don’t worry—this process isn’t as complicated as it ...

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, 4th Edition

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

John L. Viescas
SQL Cookbook, 2nd Edition

SQL Cookbook, 2nd Edition

Anthony Molinaro, Robert de Graaf

Publisher Resources

ISBN: 9781633438576Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentPurchase Link