Subqueries as Column Expressions
In Chapter 5, Getting More Than Simple Columns, you learned a lot about using expressions to generate calculated columns to be output by your query. We didn’t tell you then that you can also use a special type of SELECT statement—a subquery—to fetch data from another table, even if the table isn’t in your FROM clause.
Syntax
Let’s go back to the basics and take a look at a simple form of a SELECT statement in Figure 11-1.
Figure 11-1. The syntax diagram for a simple SELECT statement
This looks simple, but it really isn’t! In fact, the value expression part can be quite complex. Figure ...
Get SQL Queries for Mere Mortals: A Hands-On Guide to Data Manipulation in SQL, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.