home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
database
/
ssql1b.zip
/
SUBQUERY.SHR
< prev
next >
Wrap
Text File
|
1988-02-09
|
2KB
|
60 lines
SUBQUERIES (SHORT VERSION)
Often, we need to break down our query into more than one
query. Each query will have its own select. We need
subqueries when, in analyzing a query, we find that we need
information from one query before we can process another query.
In some cases we can either join tables or use a subquery.
Typically, subqueries retrieve information more rapidly than
joining tables.
Subqueries work "backwards" in that the last select statement is
executed first and so on.
Assume you have the following query: Which customers have
purchased products from salespersons who work under manager
number 20? One approach would be to find all the salespeople
that have the same number as one of the group of employees in
the employee table who have a 20 in the mgrn column.
select distinct cc
from s
where sn in
(select enum
from e
where mgrn = 20);
cc
--
c2
1 row selected
Subqueries can be used in a variety of ways to extract data that
would otherwise be unavailable. Become a registered user and
find out all the details.
SUBQ-1