Wednesday, June 10, 2009

Reading Data

The Open SQL statement for reading data from database tables is:

SELECT
INTO
FROM
[WHERE ]
[GROUP BY ]
[HAVING ]
[ORDER BY ].

The SELECT statement is divided into a series of simple clauses, each of which has a different part to play in selecting, placing, and arranging the data from the database.

This graphic is explained in the accompanying text

Clause

Description

SELECT

The SELECT clause defines the structure of the data you want to read, that is, whether one line or several, which columns you want to read, and whether identical entries are acceptable or not.

INTO

The INTO clause determines the target area into which the selected data is to be read.

FROM

The FROM clause specifies the database table or view from which the data is to be selected. It can also be placed before the INTO clause.

WHERE

The WHERE clause specifies which lines are to be read by specifying conditions for the selection.

GROUP BY

The GROUP-BY clause produces a single line of results from groups of several lines. A group is a set of lines with identical values for each column listed in .

HAVING

The HAVING clause sets logical conditions for the lines combined using GROUP BY.

ORDER BY

The ORDER-BY clause defines a sequence for the lines resulting from the selection.

The individual clauses and the ways in which they combine are all very important factors in the SELECT statement. Although it is a single statement like any other, beginning with the SELECT keyword and ending with a period, its division into clauses, and the ways in which they combine, make it more powerful than other statements. A single SELECT statement can perform functions ranging from simply reading a single line to executing a very complicated database query.

You can use SELECT statements in the WHERE and HAVING clauses. These are called subqueries.

You can decouple the INTO clause from the SELECT statement by reading from the database using a cursor.

On certain database systems, locking conflicts can also occur when only reading the data. These can be avoided by using database commits.

No comments:

Blog Archive