Question : Which clause is used to sort the result-set in SQL?
Solution :
Correct Answer : ORDER BY
Description -
Question : What is the default sorting order of ORDER BY?
Solution :
Correct Answer : ASC
Description -
Question : Which keyword is used for descending order sorting?
Solution :
Correct Answer : DESC
Description -
Question : Which query sorts employee names alphabetically?
Solution :
Correct Answer : SELECT * FROM employees ORDER BY name;
Description -
Question : What will the following query do?
SELECT * FROM products
ORDER BY price DESC;
Solution :
Correct Answer : Sort by highest price first
Description -
Question : Which statement about ORDER BY is TRUE?
Solution :
Correct Answer : It sorts rows
Description -
Question : Which clause is commonly used with ORDER BY to restrict output rows?
Solution :
Correct Answer : LIMIT
Description -
Question : What does the following query return?
SELECT * FROM students
ORDER BY marks DESC
LIMIT 1;
Solution :
Correct Answer : Highest marks student
Description -
Question : Which query sorts data randomly in MySQL?
Solution :
Correct Answer : ORDER BY RAND()
Description -
Question : Which function is commonly used in PostgreSQL for random ordering?
Solution :
Correct Answer : RANDOM()
Description -
Question : Which query sorts by two columns?
Solution : SELECT * FROM emp
Correct Answer :
ORDER BY dept, salary;
Description -
Question : What is the sorting priority here?
ORDER BY department ASC, salary DESC;
Solution :
Correct Answer : Department first
Description -
Question : Which query gives the top 3 highest salaries?
Solution : SELECT * FROM emp
Correct Answer :
ORDER BY salary DESC
LIMIT 3;
Description -
Question : Which clause must come after ORDER BY?
Solution :
Correct Answer : LIMIT
Description -
Question : What happens if duplicate values exist in the sorted column?
Solution :
Correct Answer : Duplicate values remain together
Description -
Question : Which query sorts names from Z to A?
Solution :
Correct Answer : ORDER BY name DESC
Description -
Question : Which symbol separates multiple columns in ORDER BY?
Solution :
Correct Answer : Comma ,
Description -
Question : Which query returns 5 random records in MySQL?
Solution : SELECT * FROM emp
Correct Answer :
ORDER BY RAND()
LIMIT 5;
Description -
Question : Can ORDER BY be used on columns not shown in SELECT?
Solution :
Correct Answer : Yes
Description -
Question : Which query correctly sorts by department ascending and name descending?
Solution :
Correct Answer : ORDER BY department ASC, name DESC;
Description -
SELECT * FROM employees
ORDER BY department ASC, name DESC;