Informatics Practices
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
SQL Queries
2 Likes
Answer
Firstly on empid and then on empname
Reason — The ORDER BY emp_id, emp_name
clause sorts the result set firstly by the emp_id
column. If there are rows with the same emp_id
, those rows are further sorted by the emp_name
column.
Answered By
2 Likes
Related Questions
Can you arrange the result set of an SQL query on multiple columns ?
What is the significance of "ORDER BY" in the given query?
SELECT emp_id, fname, lname FROM person ORDER BY emp_id;
(a) Data of table person on the basis of column emp_id will be sorted in descending order
(b) Data of table person on the basis of column emp_id will be sorted in ascending order
(c) Only data of column emp_id will be sorted in descending order
(d) Only data of column emp_id will be sorted in ascending order
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
Which function can you use with ORDER BY clause to specify custom sort order ?
(a) SORT()
(b) CUSTOM()
(c) FIELD()
(d) All of these