Using ORDER BY clause in a different aspect

Anar Məmmədov
2 min readNov 27, 2022

--

As we know ORDER BY clause sorts the result set ASC|DESC in SQL and every time we see that there are a lots of topics about ORDER BY clause the same way. We are going to talk about in a different way in today this article. Suppose we want to sort the result set in a different aspect where you don’t see have been anywhere. So without further ado let’s get started.

Suppose you have a task and they want to that you sort the result set where the any column of the any table which it’s columns of character size is maximum. What do you do in this situation? Think about it.

Suppose we have table EMPLOYEE like the following:

EMPLOYEE TABLE

and we want to sort the result set- where ENAME column contains maximum character. In order to do that write query like the following:

SELECT DISTINCT

ename

FROM emp

ORDER BY LENGTH(ename) DESC;

and results are be able to like this:

RESULT AFTER THAT

--

--

Anar Məmmədov
Anar Məmmədov

Written by Anar Məmmədov

Java Backend Developer wondering RDBMS and processing of structure any technology that is related backend.