in Databases edited by
19,098 views
28 votes
28 votes

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{Student_name}\\\hline 1 & \text{Amit} \\\hline 2 & \text{Priya} \\\hline 3 & \text{Vinit} \\\hline 4 & \text{Rohan} \\\hline 5 & \text{Smita} \\\hline \end{array}} \qquad\overset{\text{Table: Performance}}{\begin{array}{|l|l|l|} \hline \text{Roll_no} & \text{Subject_code} & \text{Marks}\\\hline 1 & \text{A} & 86 \\\hline 1 & \text{B} & 95 \\\hline 1 & \text{C} & 90 \\\hline 2 & \text{A} & 89 \\\hline 2 & \text{C} & 92 \\\hline 3 & \text{C} & 80 \\\hline \end{array}}$$

The primary key of the Student table is Roll_no. For the performance table, the columns Roll_no. and Subject_code together form the primary key. Consider the SQL query given below:

SELECT S.Student_name, sum(P.Marks) 
FROM Student S, Performance P 
WHERE P.Marks >84 
GROUP BY S.Student_name;

The number of rows returned by the above SQL query is ________

in Databases edited by
by
19.1k views

4 Comments

arjun sir pls reply
0
0

That is on natural join, here cross product is considered as join condition is not given.

0
0
But sir,..when written in ques is join and we find two table having same attribute (here is Roll no.) ..then we do natural join . If not,plz explain.
0
0

5 Answers

35 votes
35 votes
Best answer
Group by Student_name $\implies$ number of distinct values of Student_name

in the instance of the relation all rows have distinct name then it should results $5$ tuples !
edited by

17 Comments

@Shaik  sir, what will be tuple values for Rohan & Smita?

Is here we have to relate tuples with primary constraint??

1
1

what will be tuple values for Rohan & Smita?

no need of tuple values to answer this query, right ?

 

Is here we have to relate tuples with primary constraint??

when we apply group by with some attributes, then in the result those attributes should be unique !

no need to bother about remaining attributes, if you use any of the remaining attributes uses in select clause, then it may generate error some times !

1
1
what are those 5 tuples? can you please write
0
0
edited by
there is only one condition which is P.Marks > 84

therefore just remove those tuples from P which are ≤ 84.

Now there are 5 tuples in the relation P.

Now Do the cross product ! ==> Total 5 x 5 = 25 tuples in the result of cartesian product after applying where clause also.

Now we have to use Group By clause.

$$\begin{array}{|l|l|} \hline \textbf{S.Student_Name} & \textbf{SUM(P.marks)} \\\hline  \text{Amit} & 86+95+90+89+92=452 \\\hline \text{Priya} & 86+95+90+89+92=452 \\\hline \text{Vinit} & 86+95+90+89+92=452 \\\hline \text{Rohan} & 86+95+90+89+92=452 \\\hline \text{Smita} & 86+95+90+89+92=452 \\\hline\end{array}$$
38
38

5 is Correct answer. I ran this query:

25
25
How do we know that we have to take cross product?
0
0
Whatever table is present in From clause you have to join all of them and filter the row, based on the condition specified in Where.
2
2

@Rahulgupta2509

FROM Student S, Performance P

from a,b,c,

means a×b×c  

 

9
9

@ sir , how u get sum 452 , please see this similar question where sum is caculated by group wise but i am not able to see that actual difference between these two queries . Please help! https://gateoverflow.in/8225/gate2015-1-27

1
1
the answer in the link also edited by me only.

i dont see any difference... both are same... after grouping, marks will be addition.
0
0
sir,in this question marks are added of all the students name together (all have same sum value) but in the linked question sum is performed after grouping of students name wise.
0
0
why sum is same for this question, why not for the question in the link ?

 

because of the where condition, it is different.

it is like natural join in question which is in the link but not in THIS question. here also sum performed after grouping.
0
0
Got it sir, thank you so much!
1
1
is this true really ??
0
0
If let’s say I have two tables and they have same attribute name and can apply natural join but cross product is given, in that case do we still apply cross product? And For the natural join are they always going to mention explicitly?
0
0
best solution
0
0
In the link given question there is condition given so it is natural join. But in the given question we consider as cross product.

Hope you understand.
0
0
20 votes
20 votes
5 rows

Comma by default means cross product not natural join

4 Comments

@Manoj Kumar Pandey

even though there are common attributes it doesn't perform natural join !

2
2
Why not? I didn’t understand the concept.
0
0
For natural join it will be explicitly mentioned or we have to assume in case of same attribute name?
0
0
6 votes
6 votes
Remember this basic rule in sql

SELECT= PROJECTION

FROM= CROSS PRODUCT

WHERE= SELECT CONDITION

here in the given query we need to take cross product which returns 25 query with keeping in mind the condition to jave marks > 84 so when we group by our answer would be

Amit 452

Priya 452

Vinit 452

Roshan 452

Smita 452

So 5 tuples
4 votes
4 votes
was it 5 I don't remember exactly. But relation Algebra was 1

4 Comments

From where did you calculate ? Response sheet or answer key pushed ?
0
0
Good Ahbanc u will be in top २०० for sure if luck favour's u will be in top १०० , I am going down one by one , Silly mistakes of calculating combination,divide etc. ruined my exam 😑
0
0
Lets see, Even I don't know all the answers. Depends on the final answer key. Everything can change. Also, it seems this time top rankers will have very high marks so less chances it seems.
0
0
Answer:

Related questions