Understanding the Power of SQL Statement Generation

Generating SQL from another SQL statement simply means writing a SQL statement whose output forms another SQL statement or command. Until now, all the SQL statements that you have learned to write either do something, such as manipulate the data in a table, one row at a time, or produce some kind of report from a query. Today, you learn how to write a query whose output forms another query or SQL statement.

Why would you ever need to produce a SQL statement from a query? Initially, it is a matter of simplicity and efficiency. You may never need to produce a SQL statement, but without ever doing so you would be ignoring one of SQL's most powerful features, one that too many people do not realize ...

Get Sams Teach Yourself SQL in 21 Days, 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.