This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Select Distinct”.
1. Which keyword is used in conjunction with DISTINCT keyword?
a) From
b) Select
c) Where
d) Group By
View Answer
Explanation: The distinct keyword is used in conjunction with select keyword. When we use distinct keyword, only the unique values are fetched.
2. Which SQL statement is used to return only different values?
a) Select Different
b) Select Unique
c) Select Distinct
d) Select
View Answer
Explanation: The SELECT DISTINCT statement is used to return only distinct values. The SELECT statement returns data without eliminating duplicates, whereas the rest are not SQL statements.
3. A column of a database table must not contain duplicate values.
a) True
b) False
View Answer
Explanation: Inside a database table, a column may contain many duplicate values. It is not mandatory that every column should have a unique value.
4. Which of the following SQL statement selects only unique values from ‘section’ column of table ‘school’?
a) SELECT section FROM school;
b) SELECT * FROM school;
c) SELECT DISTINCT section FROM school;
d) SELECT ALL section FROM school;
View Answer
Explanation: Distinct keyword along with Select clause returns only distinct values. All keyword when used with select clause returns all values without eliminating the duplicates. * Results all the fields of a table without eliminating duplicates.
5. When more than one expression is provided in the DISTINCT clause, the query will retrieve _________
a) Unique values for any one of the expression
b) Unique combinations for the expressions listed
c) All values for any one of the expression
d) All combinations for the expressions listed
View Answer
Explanation: When only one expression is provided in the DISTINCT clause, the query will return the unique values for that expression. When more than one expression is provided in the DISTINCT clause, the query will retrieve unique combinations for the expressions listed.
6. In SQL, the DISTINCT clause ignores NULL values.
a) True
b) False
View Answer
Explanation: In SQL, the DISTINCT clause doesn’t ignore NULL values. So when using the DISTINCT clause in SQL statement, our result set will include NULL as a distinct value.
7. DISTINCT clause considers NULL as ________
a) Zero value
b) A unique value
c) Some default value
d) A space character
View Answer
Explanation: A field with a NULL value is the one that has been left during record creation. SQL Distinct clause treats NULL as a unique value. So when using the DISTINCT clause in SQL statement, our result set will include NULL as a distinct value.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.