Informatics Practices
Which function can you use with ORDER BY clause to specify custom sort order ?
(a) SORT()
(b) CUSTOM()
(c) FIELD()
(d) All of these
SQL Queries
2 Likes
Answer
FIELD()
Reason — The FIELD()
function in SQL allows to specify a custom sort order by listing the values in the order we want them to appear.
For example, the following statement selects column fruit_name
from the fruits
table and orders the result set based on the custom sort order specified by the FIELD()
function.
SELECT * FROM fruits
ORDER BY FIELD(fruit_name, 'Apple', 'Banana', 'Orange', 'Grapes');
Answered By
1 Like
Related Questions
What will be the order of sorting in the given query?
SELECT emp_id, emp_name FROM person ORDER BY emp_id, emp_name;
(a) Firstly on empid and then on empname
(b) Firstly on empname and then on empid
(c) Firstly on empid but not on empname
(d) None of the mentioned
If column emp_id contains the following set {9, 7, 6, 4, 3, 1, 2}, what will be the output on execution of the given query?
SELECT emp_id FROM person ORDER BY emp_id;
(a) {9, 7, 6, 4, 3, 1, 2}
(b) {1, 2, 3, 4, 6, 7, 9}
(c) {2, 1, 4, 3, 7, 9, 6}
(d) None of these
By default, ORDER BY clause lists the results in …………… order.
- Descending
- Any
- Same
- Ascending
Which one of the following would arrange the rows in ascending order in SQL ?
- SORT BY
- ALIGN BY
- GROUP BY
- ORDER BY