O'Reilly logo

SQL: Visual QuickStart Guide by Chris Fehily

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Subqueries

To this point, I’ve used a single SELECT statement to retrieve data from one or more tables. In this chapter, I’ll describe nested queries, which allow you to retrieve or modify data based on another query’s result.

A subquery is a SELECT statement embedded in another SQL statement. You can nest a subquery in:

  • The SELECT, FROM, WHERE, or HAVING clause of another SELECT statement

  • Another subquery

  • An INSERT, UPDATE, or DELETE statement

In general, you can use a subquery anywhere an expression is allowed, but your DBMS may place specific restrictions on where subqueries may appear. I’ll cover subqueries nested in a SELECT statement or another subquery in this chapter, and subqueries embedded in INSERT, UPDATE, and DELETE statements ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required