ASET Relational databases and relational algebra Relational Query
ASET Relational databases and relational algebra
Relational Query Languages ASET n Query languages are languages that are used to write database queries that return desired data from the database. n “Pure” languages: l Relational algebra l Tuple relational calculus l Domain relational calculus n Relational operators
ASET Relational Algebra
Selection of tuples ASET n Relation r n Select tuples with A=B and D > 5 l σ A=B and D > 5 (r)
Selection of Columns (Attributes) ASET n Relation r: n Select A and C l Projection l Π A, C (r)
Joining two relations – Cartesian Product ASET n Relations r, s: n r x s:
Union of two relations ASET n Relations r, s: n r s:
Set difference of two relations ASET n Relations r, s: n r – s:
Set Intersection of two relations ASET n Relation r, s: n r s
Joining two relations – Natural Join ASET n Let r and s be relations on schemas R and S respectively. Then, the “natural join” of relations R and S is a relation on schema R S obtained as follows: l Consider each pair of tuples tr from r and ts from s. l If tr and ts have the same value on each of the attributes in R S, add a tuple t to the result, where 4 t has the same value as tr on r 4 t has the same value as ts on s
Natural Join Example ASET n Relations r, s: n Natural Join l r s
Figure in-2. 1 ASET
- Slides: 12