Subquery Rules

Now that you've explored simple and correlated subqueries and have compared them to joins, look more closely at the rules governing subqueries. They primarily concern the SELECT list of the nested subquery, with some additional restrictions on functions that you can specify in a subquery. Your SQL dialect may have more or fewer restrictions, but here are some of the common ones:

  • The SELECT list of an inner subquery introduced with a comparison operator or IN can include only one expression or column name. The column you name in the WHERE clause of the outer statement must be join-compatible with the column you name in the subquery SELECT list.

  • Subqueries introduced by an unmodified comparison operator (a comparison operator not ...

Get Practical SQL Handbook, The: Using SQL Variants, Fourth 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.