KnowledgeBoat Logo
|
LoginJOIN NOW

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