in Databases edited by
2,695 views
36 votes
36 votes

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.
  4. Customers who do not buy buy anything at all.
  5. None of the above.
in Databases edited by
2.7k views

4 Comments

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.
0
0
@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
0
0
This one is really nice question.
1
1

5 Answers

33 votes
33 votes
Best answer

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.

selected by

4 Comments

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

0
0

Customers who buy from all shops. already includes no output case.

1
1

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

0
0
17 votes
17 votes

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

4 votes
4 votes

Ans is C

by
2 votes
2 votes

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

Buys

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

final answer 

C

1 comment

Nice explanation, thanks!
0
0
Answer:

Related questions