Using scalar aggregate functions to guarantee a single value  Using distinct with expression subqueries

Chapter 5: Subqueries: Using Queries Within Other Queries

Using group by and having in expression subqueries

Because subqueries that are introduced by unmodified comparison operators must return a single value, they cannot include group by and having clauses unless you know that the group by and having clauses will return a single value.

For example, this query finds the books that are priced higher than the lowest priced book in the trad_cook category:

select title 
from titles 
where price > 
   (select min(price) 
    from titles 
    group by type 
    having type = "trad_cook")




Copyright © 2005. Sybase Inc. All rights reserved. Using distinct with expression subqueries

View this book as PDF