2,695 views

In a relational database there are three relations:

• $Customers = C \textsf{(CName)}$
• $Shops = S \textsf{(SName)}$
• $Buys = B \textsf{(CName, SName)}$

Then the Relational Algebra expression ( $\Pi$ is the projection operator).

$C-\Pi _\textsf{CName}((C \times S)-B)$

returns the names of

1. Customers who buy from at least one shop.
2. Customers who buy from at least two shops.
3. Customers who buy from all shops.
5. None of the above.

The key point here is we don't have to take a tuple in the customer who don't visit any of the shop else Relation algebra expression will give different solution.
So they do not consider entries customer who don't visit any of the shops or he must visit at least one shop for being a part of the customer relation.
@bikram sir

∏Cname (C*S-B ) will give names of customers who do not went to all shops . So in your table it will give A and B as both A and B did not went to all shops where C went to all shops

Why it project only A,B  it should project all tuple of Customer attribute
This one is really nice question.

It is division in relational algebra
Division = ${\pi_{AB}} (R) /{\pi_ {B}} (S)$      Results in 'A' values for which here should be 'B' in R for every 'B' of S.

${\pi _{AB}}(R)/{\pi_{B}} (S) = {\Pi _{A}}(R) -{\pi _ {A}}({\pi _ {A}}(R)\times S-R)$  Retrieve all A's who are related to every B

$C−{\Pi_{CName}}((C\times S)−B)$

$C\times S$ gives the complete relation of each customer to every shop

$(C\times S)−B)$ :gives the relation of the customer which is not related to every shop.

${\Pi_{CName}}((C\times S)−B)$: gives the customer name who is not related to every shop.

$C−{\Pi_{CName}}((C\times S)−B)$: gives the customer who is related to every shop.

Option C) Customers who buy from all shops.

So answer will be either "no output" or Customers who buy from all shops.

this question has some match https://gateoverflow.in/25872/tifr2013-b-19

lets solve by taking example

Customer

 Customer name A B C

Shop

 name 1 2

C*S will be possible combinations of customers and shop(cartesian product)

∏name (C*S-B ) will give names of customers who do not went to all shop in our example its  B and C

now when we C-∏name (C*S-B ) we get A as output

so output will be name of employees who went to every shop

Ans is C

by

According to me Best approach to solve such question  is by taking example which includes all possible options.

In case one of option is given "none of above" in that case be also check whether final answer returns null , or multiple value.

This approach is time taking but gives correct result.

customers : A,B,C,D  shops:  P1,P2,P3

 A P1 B P2 B P2 C P1 C P2 C P3

reason why only this table taken

first row :

Customers who buy from at least one shop. -> then A must be there, and D will not be there

second and third row

Customers who buy from at least two shops.-> then B will be there and A, D will not be there

4,5,6th

Customers who buy from all shops. -> then C will be there A, B, D will not be there.

No row for D:

Customers who do not buy buy anything at all. ->D will be  there A, B, C will not be there

ΠCName((C×S)−B)

gives

 A P2 A P3 B P1 D P1 D P2 D P3

I know projection will return just (A, B, D) , but for understanding purpose i have written like this

C

### 1 comment

Nice explanation, thanks!