SQL & # 8594; Relational algebra

Suppose I have the following relationships:

Branch (branchNo(PK), street, city, postcode) Staff (staffNo(PK), fName, lName, sex, branchNo(FK)) 

Not that this is important for this question, but PK = primary key and FK = foreign key

How to write relational algebra for the following query:

List the names of all female employees who work in Glasgow.

My attempt:

Οƒ Staff.sex=F & Branch.city = Glasgow (Ο€ fName, lName, sex, branchNo (Staff) x Ο€ city, branchNo (Branch))

I know that my selection (Οƒ) statement (SHOULD NOT BE ELIMINATED WITH SELECT) is syntactically incorrect:

 ΟƒStaff.sex=F & Branch.city = Glasgow 

How to write two choices for a different relationship? Or, in other words, how to express an SQL statement with two or more conditions in a WHERE clause in relational algebra? I used '&' but it can't be right? Should I embed one choice in another?

NOT HOMEWORK

+4
source share
1 answer

Formal relational algebra uses logical conjunction and disjunction and (usually) symbols for them ( & and; and & or;, respectively), although authors can choose their own syntax. The request can be written as:

Ο€ fName, lName (Οƒ (gender=F ∧ city=Glasgow) (Staff β‹ˆ Branch))

Note that x (rather, β¨―) is the symbol for Cartesian product. For natural joins, you want β‹ˆ (bowtie).

If you want a Cartesian product, not a natural join, you basically implement a natural join by adding the appropriate condition to the selection. You also need to deal with the fact that the branchNo attribute is common to both relationships, which you can do using

+6
source

All Articles