This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Order By Clause”.
1. Which SQL keyword is used to sort the data returned by a SELECT statement?
a) Order By
b) Group By
c) Order
d) Group
View Answer
Explanation: Order By clause is used to sort the retrieved data in ascending or descending order. Group By clause is used to group the result-set by one or more columns. Order and Group are not valid SQL commands.
2. What is the default ordering of data using ORDER BY clause?
a) Descending order
b) Random order
c) Ascending order
d) No change
View Answer
Explanation: The ORDER BY keyword sorts the records in ascending order by default. It can be changed by using DESC keyword, after the column name in ORDER BY clause.
3. To sort the records in descending order, which keyword is used?
a) Descend
b) Increase
c) Desc
d) Order
View Answer
Explanation: DESC keyword is used after the column name in ORDER BY clause to sort the records in descending order. Otherwise, records will be sorted in ascending order by default.
4. Which one of the following sorts rows in SQL?
a) Sort By
b) Align By
c) Group By
d) Order By
View Answer
Explanation: Order By is used to sort the rows of result-set in SQL. Group By clause is used to group the result-set by one or more columns. Sort By and Align By are not valid SQL commands.
5. The columns specified in ORDER BY clause may or may not be the columns specified in the SELECT column list.
a) True
b) False
View Answer
Explanation: ORDER BY clause is used to sort the selected columns in ascending or descending order. The columns specified in ORDER BY clause may or maynot be the columns selected in the SELECT column list.
6. Aliases defined in the SELECT Statement can be used in ORDER BY Clause.
a) True
b) False
View Answer
Explanation: Column Alias could be used in Order By clause. New name of the Attribute stated in the SELECT statement is to be used with ORDER BY clause to sort the result-set in ascending or descending order.
7. Which of the following can be used with the ORDER BY clause in place of column name?
a) Row name
b) Table name
c) Column position in the columns list
d) Attribute name
View Answer
Explanation: Instead of using column name in the ORDER BY clause, we can use the column position in the columns list of SELECT statement. Both of them yields the same result.
8. To sort the result with respect to multiple columns, they must be separated using ____
a) |
b) ,
c) ;
d) _
View Answer
Explanation: To sort according to multiple columns, column names must be separated using (,) operator. For example, to sort by two columns (column1 and column2), this syntax is used:
SELECT * FROM TABLE_NAME ORDER BY column1, column2;
9. When sorting the result set using the SQL ORDER BY clause, we can use ___________ attributes in a single SELECT statement.
a) Only Asc not Desc
b) Only Desc not Asc
c) None of Asc and Desc
d) Both Asc and Desc
View Answer
Explanation: Both Asc and Desc attributes can be used in a single SELECT statement to sort the result-set using ORDER BY clause. Attributes with Asc keyword will be sorted in Ascending order and the Attributes with Desc keyword will be sorted in Descending order.
10. Which of the following order is valid and yields correct results in SQL?
a) Select, from, order by, where
b) Select, from, where, order by
c) Select, order by, from
d) From, order by, where
View Answer
Explanation:
SELECT * FROM TABLE_NAME WHERE conditions ORDER BY column_name ASC|DESC;
This is the correct syntax for a basic SQL statement with ORDER BY clause. Hence the order should be Select, from, where, order by.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]