Databases Reference
In-Depth Information
6
Chapter
Advanced SQL Queries
In This Chapter
Subqueries
Correlated subqueries
Multiple-column subqueries
In the previous chapter, you saw how you can write queries that retrieve
information from multiple tables. This chapter looks at more advanced
types of queries. We will begin with relatively simple subqueries, which
allow you to put one query inside another, rather than running two indi-
vidual queries. Subqueries can be tied even more closely to the main
query using a correlated subquery, where columns in the
Set operators:
UNION
,
INTERSECT
, and
MINUS
Summarizing tables using
ROLLUP
and
CUBE
WHERE
clause of
the subquery directly reference columns in the main query.
Sometimes, you need to get similar information from more than one
query, and there is some overlap between the results. You might not want
to see the duplicates, or you might want to see only the results that two
queries have in common. As you'll learn here, you can use
UNION
and
INTERSECT
to accomplish these tasks. You'll also learn how to use
ROLLUP
and
CUBE
to summarize table information.
Search WWH ::




Custom Search