Working with a subquery

A subquery is a very useful tool to solve certain special problems. It can return values to form a condition or to add a column. There are mainly three different usages:

  • Subquery under a Where clause
  • Subquery as a standalone column
  • Subquery within a subquery

    Tip

    Although you can add a subquery within a subquery and the level for subquery can be more than two, it is not recommended. The more sublevels that exist in your query, the more trouble you may end up with. It is not worth the effort to create such a monster-like query unless you do not have any other choice.

The following query example cases belong to the first two categories. No subquery within a subquery is shown here due to the obvious reason just mentioned.

Case 9-S1—Item ...

Get Mastering SQL Queries for SAP Business One 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.