retagged by
2,143 views
4 votes
4 votes
Let R(a,b) be a schema and Q1 and Q2 are queries on R.

Q1: SELECT * FROM R;

Q2: (SELECT * FROM R) INTERSECT (SELECT * FROM R);

Which of the following statements is true?

(A) Q1 and Q2 produce the same answer.

(B) The answer to Q1 is always contained in the answer to Q2.

(C) The answer to Q2 is always contained in the answer to Q1.

(D) Q1 and Q2 produce different answers.

ans = C given

please explain the logic behind
retagged by

3 Answers

3 votes
3 votes
Intersection is a set operation and set doesnt contain duplicate values. Q1 will print all the rows including those which are duplicates i.e there may be some rows in its output that might be repeated. In Q2 duplicate rows are printed only once i.e there will be no repeatition. |Q2|<=|Q1| and hence result of Q2 will always be contained in Q1.

If instead of 'Intersect' we have used 'Intersect All' then duplicacy will be allowed and Q1 and Q2 will produce same result.
1 votes
1 votes
when your are using the intersection operator duplicates are removed so...

simply the first query gives u all the rows including duplicates

second query gives u all the rows from R without duplicates hence c is the answer

Related questions

6 votes
6 votes
1 answer
1
indrajeet asked Sep 22, 2016
756 views
Consider the following table MysteryMysteryAB1Null2435Null6select count() from Mysterywhere A not in( select B from Mystery)(A) 1(B) 0(C) 4(D) 3ans is B givenplease expla...
0 votes
0 votes
0 answers
2
Beyonder asked Nov 30, 2016
705 views
Can Anyone Explain how Query 28 works with example.
0 votes
0 votes
1 answer
3
aditya kuppa 1 asked Dec 5, 2017
1,043 views
How many minimum tables are required for this er diagram consisting of a many - many relation and total participation of one of the entities.? Can't i merge relation R an...
2 votes
2 votes
2 answers
4
indrajeet asked Sep 23, 2016
3,265 views
Consider the following entity relation diagramIf A has 50 entities,B has 20 entities and C has 200 entities. what is the maximum number of triples of entities that could ...