0

I'm trying to understand when to use the selection and projection operators. My current understanding is that selection returns tuples that fit a specified criteria, and projection creates a new relation from the relation it acts upon, but only with the attributes specified. For example:

σ(attribute="criteria"^(relation)) 

returns all tuples with the specified attribute value, from relation "relation".

Π name (relation) 

would find the list of names from the relation "relation", disregarding the any other attributes.

From this sample database, with asterisk-marked primary keys:

employee(*personName*, street, city)
works(*personName*, companyName, salary)
company(*companyName*, city)
manages(*personName*, managerName)

I have to:

A) Find the names of all employees who work for M&T Bank.

Π personName(σcompanyName = “M&T Bank” ^(works))

B) Find the names of all companies which might be recorded in the database.

Π companyName (company)

C) Find the names of all employees who are not managers.

Π personName (works) - ΠpersonName(manages)

Basically, are the above query attempts right? And is my understanding of these operators correct and complete?

1 Answer 1

0

Answer A) is correct (also I do not know what is the meaning of ^ in your notation, so I've just ignored it).

For B you should keep in mind that the companies might be recorded not only in the company table but also in the works table. Hence, your answer should be Π companyName (company) U Π companyName (works).

For C you should also be a bit more careful with identifying the employees. One could argue that former employees still listed in employee but not in works should also be considered. Depending on your (or your teacher's) point of view you might need to use Π personName (works) U Π personName (employee) instead of Π personName (works).

A more serious issue in C is the identification of managers. ΠpersonName(manages) are individuals being managed, not managers. Managers are Π managerName(manages).

Hence, for C you might prefer (Π personName (works) U Π personName (employee)) - Π managerName(manages).

In general, your understanding of projection and selection is correct, but you need to be slightly more careful when formulating the answers.

1
  • The carat was supposed to mark a superscript; sorry if that was unclear. This all makes sense, though; thank you so much for your helpful reply.
    – HB-
    Sep 11, 2014 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.