Data sorting
Another aspect of manipulating data is properly sorting it in order to clearly identify important facts, such as top the N values, maximum, minimum, and so on. HQL supports the following keywords for data sorting:
ORDER BY [ASC|DESC]
: It is similar to the SQLORDER BY
statement. When usingORDER BY
, a sorted order is maintained across all of the output from every reducer. It performs a global sort using only one reducer, so it takes longer to return the result. The direction specifier afterORDER BY
can be eitherASC
for ascending (low to high) orDESC
for descending (high to low). If you do not provide a direction specifier, the default of ascending is used. Since v2.1.0, theORDER BY
statement supports specifying the sorting direction for theNULL
value, such asNULL FIRST
orNULL LAST
. By default,NULL
stays at the first place in theASC
direction and the last place in theDESC
direction:
> SELECT name FROM employee ORDER BY name DESC; -- By columns +-------...