Sunday , December 22 2024

Order By PostgreSQL

In today’s article, we will learn how to sort data with the Order By command in PostgreSQL.

With the Order By command, this order can be sorted from smallest to largest or alphabetically.

General Usage is as follows.

The ORDER BY command takes two parameters:

ASC: ASC command is the abbreviation of the word ASCENDIG.

With this parameter, we can sort textual expressions alphabetically from smallest to largest.

DESC: DESC command is the abbreviation of the word DESCENDIG.

With this parameter, we can sort textual expressions alphabetically from largest to smallest.

You can use asc and desc parameters in the table as follows.

ORDER BY columnName asc

To sort in more than one column:

ORDER BY column1 asc or desc, column2 asc or desc

Let’s reinforce it with an example.

First, let’s create our table.

Let’s add our data to our ascdescörnek table.

Let’s see how our data is sorted by sorting the textt column in our table as desc.

As seen above, we sorted the text column as desc, and our other column is affected by this and performs the sorting process as desc.

Let’s list the numerical value in column 1 as asc.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *