Selection (relational algebra)
Encyclopedia
In relational algebra
Relational algebra
Relational algebra, an offshoot of first-order logic , deals with a set of finitary relations that is closed under certain operators. These operators operate on one or more relations to yield a relation...

, a selection (sometimes called a restriction to avoid confusion with SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....

's use of SELECT) is a unary operation
Unary operation
In mathematics, a unary operation is an operation with only one operand, i.e. a single input. Specifically, it is a functionf:\ A\to Awhere A is a set. In this case f is called a unary operation on A....

 written as
or where:
  • and are attribute names
  • is a binary operation
    Binary operation
    In mathematics, a binary operation is a calculation involving two operands, in other words, an operation whose arity is two. Examples include the familiar arithmetic operations of addition, subtraction, multiplication and division....

     in the set
  • is a value constant
  • is a relation


The selection selects all those tuple
Tuple
In mathematics and computer science, a tuple is an ordered list of elements. In set theory, an n-tuple is a sequence of n elements, where n is a positive integer. There is also one 0-tuple, an empty sequence. An n-tuple is defined inductively using the construction of an ordered pair...

s in for which holds between the and the attribute.

The selection selects all those tuples in for which holds between the attribute and the value .

For an example, consider the following tables where the first table gives the relation , the second table gives the result of and the third table gives the result of .
|- style="text-align: center"
|
|
|
|- style="vertical-align: top"
|
{| border=0 cellpadding=10 cellspacing=0 style="border-collapse: collapse; border: 1px solid black"
|- style="background-color: silver; text-align: left"
! style="border: 1px solid black" width="34%" | Name
! style="border: 1px solid black" width="33%" | Age
! style="border: 1px solid black" width="33%" | Weight
|-
| style="border: 1px solid black" | Harry
| style="border: 1px solid black" | 34
| style="border: 1px solid black" | 80
|-
| style="border: 1px solid black" | Sally
| style="border: 1px solid black" | 28
| style="border: 1px solid black" | 64
|-
| style="border: 1px solid black" | George
| style="border: 1px solid black" | 29
| style="border: 1px solid black" | 70
|-
| style="border: 1px solid black" | Helena
| style="border: 1px solid black" | 54
| style="border: 1px solid black" | 54
|-
| style="border: 1px solid black" | Peter
| style="border: 1px solid black" | 34
| style="border: 1px solid black" | 80
|}>


More formally the semantics of the selection is defined as
follows:



The result of the selection is only defined if the attribute names that it mentions are in the heading of the relation that it operates upon.

In computer languages it is expected that any truth-valued expression be permitted as the selection condition rather than restricting it to be a simple comparison.

In SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....

, selections are performed by using WHERE
Where (SQL)
A WHERE clause in SQL specifies that a SQL Data Manipulation Language statement should only affect rows that meet specified criteria. The criteria are expressed in the form of predicates...

definitions in SELECT
Select (SQL)
The SQL SELECT statement returns a result set of records from one or more tables.A SELECT statement retrieves zero or more rows from one or more database tables or database views. In most applications, SELECT is the most commonly used Data Manipulation Language command...

, UPDATE
Update (SQL)
An SQL UPDATE statement changes the data of one or more records in a table. Either all the rows can be updated, or a subset may be chosen using a condition.The UPDATE statement has the following form:...

, and DELETE
Delete (SQL)
In the database structured query language , the DELETE statement removes one or more records from a table. A subset may be defined for deletion using a condition, otherwise all records are removed.-Usage:The DELETE statement follows the syntax:...

statements, but note that the selection condition can result in any of three truth values (true, false and unknown) instead of the usual two.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK