retagged by
14,153 views
32 votes
32 votes
Consider the following relations $P(X,Y,Z), Q(X,Y,T)$ and $R(Y,V)$.

$$\overset{\textbf{Table: P}}{\begin{array}{|l|l|l|} \hline \textbf{X} & \textbf{Y} & \textbf{Z} \\\hline \text{X1} & \text{Y1} & \text{Z1} \\\hline \text{X1} & \text{Y1} & \text{Z2} \\\hline \text{X2} & \text{Y2} & \text{Z2} \\\hline \text{X2} & \text{Y4} & \text{Z4} \\\hline  \end{array}} \qquad \overset{\textbf{Table: Q}}{\begin{array}{|l|l|l|} \hline  \textbf{X} & \textbf{Y} & \textbf{T} \\\hline \text{X2} & \text{Y1} & 2 \\\hline \text{X1} & \text{Y2} & 5 \\\hline \text{X1} & \text{Y1} & 6 \\\hline \text{X3} & \text{Y3} & 1 \\\hline  \end{array}} \qquad \overset{\textbf{Table: R}}{\begin{array}{|l|l|} \hline \textbf{Y} & \textbf{V}  \\\hline \text{Y1} & \text{V1} \\\hline \text{Y3} & \text{V2} \\\hline \text{Y2} & \text{V3} \\\hline \text{Y2} & \text{V2} \\\hline  \end{array}}$$

How many tuples will be returned by the following relational algebra query?

$\Pi_x (\sigma_{(P.Y=R.Y \wedge R.V=V2))} (P \times R)) – \Pi_x (\sigma_{(Q.Y = R.Y \wedge Q.T>2))} (Q \times R))$

Answer: ________
retagged by

2 Answers

Best answer
40 votes
40 votes
$R \cdot V = V2$, there are two tuples which have $Y$ parameter as $Y3$ and $Y2$.

$P \cdot  Y = R \cdot Y$, there are no coincide with $Y3$, and there is one tuple coincide with $Y2$ which have $X$ parameter as $X2$.

$\Pi_X (\sigma _{(P.Y=R.Y\; \Lambda \;R.V = V2)}(P \times R)) = \{X_2\}$

$Q \cdot T > 2$, there are two tuples which have $Y$ parameter as $Y1$ and $Y2$ which have $X$ parameter as $X1$.

check atleast one tuple is matched $Q.Y=R.Y$ in this query, that's enough to result $X1$.

$\Pi_X (\sigma _{(Q.Y=R.Y\; \Lambda \;Q.T >2)}(Q \times R)) =  \{X_1\}$

$\Pi_X (\sigma _{(P.Y=R.Y\; \Lambda \;R.V = V2)}(P \times R)) - \Pi_X (\sigma _{(Q.Y=R.Y\; \Lambda \;Q.T >2)}(Q \times R)) = \{X_2\} - \{X_1\} = \{X_2\}$

Number of Tuples $= 1$
edited by
0 votes
0 votes

At last, (X1 X1 X2 X2) - (X1 X1 X1) will be executed leading to result of only 1 tuple i.e X2.

Answer:

Related questions

39 votes
39 votes
5 answers
1
Arjun asked Feb 7, 2019
27,268 views
A relational database contains two tables Student and Performance as shown below:$$\overset{\text{Table: student}}{\begin{array}{|l|l|} \hline \text{Roll_no} & \text{Stud...
40 votes
40 votes
4 answers
3
18 votes
18 votes
4 answers
4