retagged by
703 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

577
views
2 answers
0 votes
Bikram asked Aug 26, 2017
577 views
Consider the following set of relations: EMP (eno, ename , dno) DEPT (dno, dname)Primary key columns are underlined and dno in EMP is a foreign key referrin...
512
views
0 answers
3 votes
Bikram asked Aug 26, 2017
512 views
Consider the relation:Exam(eid, marks)Assume that marks take not null integers only. Also, marks takes distinct values and the number of tuples are odd.Select marks from ...
574
views
1 answers
7 votes
Bikram asked Aug 26, 2017
574 views
Consider the table ‘employee’ having two columns: 'EmpNo' and 'EmpName'.Run the following transaction on the table:COMMIT; ALTER TABLE employee ADD PhoneNo varchar(10...
441
views
1 answers
2 votes
Bikram asked Aug 26, 2017
441 views
Consider the following relation schema:Student (RollNo, Sname, Scity) Packages (Pcode, Pname, Price) Registers (RollNo PCode, Date) What does the following SQL quer...