Database Reference
In-Depth Information
Relational
Calculus
Format
{ r.SalespersonName : r IN SALESPERSON AND r.SalesOffice
=
'Los Angeles' }
SELECT
SalespersonName
SALESPERSON
Structured
Query
Language
Syntax
FROM
WHERE SalesOffice
=
'Los Angeles'
SELECT- Lists the columns from base tables to be projected into the result relation.
FROM - Identifies tables from which columns will be chosen.
WHERE - Includes the conditions for row selection within a single table and
conditions between tables for joining
Figure 13-10
Query in relational calculus and in SQL.
tion of all columns from the base table. The operation corresponds to the
project operation of relational algebra.
FROM This clause identifies the table or tables from which rows and columns
will be chosen. The operation corresponds to the Cartesian product operation
of relational algebra.
WHERE This clause includes the conditions for row selection within a single
table or for joining two tables. The clause corresponds to the select or join
operations of relational algebra.
Figure 13-10 shows the correspondence between the components of a relational
calculus expression and the basic structure of an SQL query. Note how the query
for the names of sales persons from the Los Angeles office is shown in the relational
calculus format and with SQL query syntax.
In addition to the three basic clauses, SQL provides a few optional clauses as
follows:
GROUP BY
To form groups of rows with the same values in given columns
HAVING
To filter the groups of rows subject to a given condition
ORDER BY
To specify the order of the rows in the result
SELECT, the most common clause in SQL, may contain specifications as to the
selection of the columns to be presented in the result set. These specifications are
indicated by the following keywords:
DISTINCT
To eliminate duplicates in the result
ALL
To state explicitly that duplicates must not be eliminated
AS
To replace a column or attribute name in the table with a new
name
In a later subsection, we will consider several examples of SQL queries—both
simple and complex. Let us now indicate the general format of the SQL query and
move on.
Search WWH ::




Custom Search