INFORMIX
Informix Guide to SQL: Tutorial
Chapter 3: Composing Advanced SELECT Statements
Home Contents Index Master Index New Book

In This Chapter

The previous chapter, "Composing Simple SELECT Statements," demonstrates some basic ways to retrieve data from a relational database with the SELECT statement. This chapter increases the scope of what you can do with this powerful SQL statement and enables you to perform more complex database queries and data manipulation.

Whereas the previous chapter focused on five of the clauses in SELECT statement syntax, this chapter adds two more. You can use the GROUP BY clause with aggregate functions to organize rows returned by the FROM clause. You can include a HAVING clause to place conditions on the values that the GROUP BY clause returns.

This chapter extends the earlier discussion of joins. It illustrates self-joins, which enable you to join a table to itself, and four kinds of outer joins, in which you apply the keyword OUTER to treat two or more joined tables unequally. It also introduces correlated and uncorrelated subqueries and their operational keywords, shows how to combine queries with the UNION operator, and defines the set operations known as union, intersection, and difference.

Examples in this chapter show how to use some or all of the SELECT statement clauses in your queries. The clauses must appear in the following order:

    1. SELECT

    2. FROM

    3. WHERE

    4. GROUP BY

    5. HAVING

    6. ORDER BY

    7. INTO TEMP

An additional SELECT statement clause, INTO, which you can use to specify program and host variables in SQL APIs, is described in Chapter 5, "Programming with SQL," as well as in the manuals that come with the product.




Informix Guide to SQL: Tutorial, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.