GATE CS 2024 Set 1 — Question 35

NAT+1 / -0EasySelection & ProjectionRelational ModelDatabasesJoins

Databases → Relational Model → Joins

Last updated

Question

Consider the following two relations, R(A,B) and S(A,C):
Relation R
AB
1020
2030
3040
3050
5095
Relation S
AC
1090
3045
4080
The total number of tuples obtained by evaluating the following expressionσB<C(RR.A=S.AS)\sigma_{B<C}(R \bowtie_{R.A=S.A} S)is _________

Correct answer

2 to 2

Solution

To evaluate the expression σB<C(RR.A=S.AS)\sigma_{B<C}(R \bowtie_{R.A=S.A} S), we first perform the natural join (equi-join on attribute AA) between relations RR and SS, and then apply the selection condition B<CB < C.
Step 1: Perform the Join (RR.A=S.ASR \bowtie_{R.A=S.A} S)
We match tuples from RR and SS where R.A=S.AR.A = S.A.
  • For A=10A=10: RR has (10,20)(10, 20) and SS has (10,90)(10, 90).
  • Resulting tuple: (A=10,B=20,C=90)(A=10, B=20, C=90)
  • For A=20A=20: RR has (20,30)(20, 30) but SS has no tuple with A=20A=20. No match.
  • For A=30A=30: RR has (30,40)(30, 40) and (30,50)(30, 50). SS has (30,45)(30, 45).
  • Match (30,40)(30, 40) with (30,45)(A=30,B=40,C=45)(30, 45) \rightarrow (A=30, B=40, C=45)
  • Match (30,50)(30, 50) with (30,45)(A=30,B=50,C=45)(30, 45) \rightarrow (A=30, B=50, C=45)
  • For A=40A=40: SS has (40,80)(40, 80) but RR has no tuple with A=40A=40. No match.
  • For A=50A=50: RR has (50,95)(50, 95) but SS has no tuple with A=50A=50. No match.
The intermediate relation after the join contains 3 tuples:
1.(10,20,90)(10, 20, 90)
2.(30,40,45)(30, 40, 45)
3.(30,50,45)(30, 50, 45)
Step 2: Apply Selection (σB<C\sigma_{B<C})
We filter the joined tuples where the value of attribute BB is strictly less than attribute CC.
1.Tuple (10,20,90)(10, 20, 90): B=20,C=90B=20, C=90. Is 20<9020 < 90? Yes.
2.Tuple (30,40,45)(30, 40, 45): B=40,C=45B=40, C=45. Is 40<4540 < 45? Yes.
3.Tuple (30,50,45)(30, 50, 45): B=50,C=45B=50, C=45. Is 50<4550 < 45? No.
Step 3: Count the Tuples
The tuples satisfying the condition are (10,20,90)(10, 20, 90) and (30,40,45)(30, 40, 45).
Total number of tuples = 2.

More questions on Relational Model

Practice GATE CS PYQs with adaptive difficulty

Timed practice, skill tracking, and AI explanations — free to start.

Start practicing free