Subqueries in update, delete, and insert statements  Subqueries instead of expressions

Chapter 5: Subqueries: Using Queries Within Other Queries

Subqueries in conditional statements

You can use subqueries in conditional statements. You can rewrite the preceding subquery that removes all records of sales of business books, as shown in the next example, to check for the records before deleting them:

if exists (select title_id 
    from titles 
    where type = "business")
begin
    delete salesdetail 
    where title_id in 
      (select title_id 
       from titles 
       where type = "business") 
end




Copyright © 2005. Sybase Inc. All rights reserved. Subqueries instead of expressions

View this book as PDF