- The SELECT clause corresponds to the projection operation of the relational algebra. It is used to list the attributes desired in the result of a query.
- The FROM clause correspond to the Cartesian-product operation of the relational algebra. It lists the relations to be scanned in the evaluation of the expression.
- The WHERE clause corresponds to the selection predicate of the relational algebra. It consists of predicate involving attributes of the relations that appears in the FROM clause.
SELECT < attribute List>
FROM < table list>
- < attribute List> is a list of attribute name whose values are retrieved by the query.
- < table list> is a list the relation names required to process the query.
- <condition> is a conditional search expression that identifies the tuples to be retrieved by the query.
In other words the same thing can be expressed as follows:
Select A1, A2……An
Each A, represents an attribute, and each r1 a relation- P is a PREDICATE. The query is equivalent to the relational-algebra expression. The query is equivalent to the relational-algebra expression
πA1, A2…….An(sp(r1 X r2 X …… rm)).
If WHERE clause is committed, the predicate P is true
The SIMPLE SELECT statements in DML
- Write a QUERY to list all the BRANCH NAMES in the loan relation.
The result of this query is a relation consisting of a single attribute with the heading br-name. This query will list each branch by-name once for every tuple in which it appears in the loan relation. In case if we want to eliminate duplicates, we use the key word DISTINCT after SELECT. We can rewrite the above query to eliminate duplicate value as
Select br-name from loan
Since duplicate retention is default, we will not use ALL. That symbol* is used to denote “all attributes”. In order to list all the attribute value of any relation we write the query as follows
Select *from loan
If we have specified more than one relation in the FROM clause, then all the attributes of all the relations are listed. The SELECT statement can also contain arithmetic expressions involving the operators +, -, *, /, and operating on constants or attributes of tuples.
Now if we have to write a query to multiply the amount attribute of all tuples in the loan relation, we can achieve the same as follows:
Select br_name, loan_no, amount*200 FROM loan