retagged by
672 views
1 votes
1 votes

Consider the table $R(p,q,w)$ and the queries given below:

Q1: SELECT DISTINCT p,q FROM R ;

Q2: SELECT p,q FROM R GROUP BY p,q ;

Then, which of the following statements are TRUE?

  1. Q1 and Q2 always produce the same result.
  2. The output of Q1 is a proper subset of the output of Q2.
  3. The output of Q2 is a proper subset of the output of Q1.
  4. Q1 and Q2 produce different results.
  1. I and II
  2. II and III
  3. I only
  4. III and IV
retagged by

1 Answer

Best answer
3 votes
3 votes

Let's take a small table.
p       q      r

1       2      1
1       2      2
1       3      2
1       3      3
2       1      4
2       3      4

Q1: SELECT DISTINCT p,q FROM R ; 
distinct will take both p,q together i.e first row is (1,2) is single unit now.

p       q

1       2
1       3
2       1
2       3

Q2: SELECT p,q FROM R GROUP BY p,q ;
Grouping by both p,q  i.e. p,q will be considered as a single unit for grouping. 
Also notice output is only p,q columns in both query.

p       q

1       2
1       3
2       1
2       3

Hence both query will have same results.

MORE: https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_distinct

try both query here.

Q1: SELECT DISTINCT OrderID,ProductID FROM OrderDetails  

Q2: SELECT OrderID,ProductID FROM OrderDetails Group By OrderID,ProductID
 

selected by
Answer:

Related questions