Sort data
To sort column data, click a sorting icon near the column name. By default, a new ORDER BY
query is sent to the database each time you click a column name. In the Services tool window (Output tab), you can see all the corresponding sorting operations.
You can also sort the data on the client side. To do that, click the Show Options Menu button () and deselect the Sort via ORDER BY option.
The column sorting is not stacked by default. It means that if you click a sorting icon near the column name to sort data by, the sorting based on other columns will be cleared. If you prefer to use the stacked sorting, click the sorting icon while pressing Alt.
State | Description |
---|---|
Indicates that the data is not sorted in this column. The initial state of the sorting marker. | |
The data is sorted in the ascending order. | |
The data is sorted in the descending order. | |
The number to the right of the marker (1 on the picture) is the sorting level. You can sort by more than one column. In such cases, different columns will have different sorting levels. |
To change the default option for stacked sorting, open settings by pressing Ctrl+Alt+S and navigate to Add columns to sorting option.
. Change the value for theAlso, you can use the ORDER BY filter and sort data in a table by writing a query in the ORDER BY field.
Sort table data with a query
In the ORDER BY field, type your query. The query syntax is the same as in the
ORDER BY
clause but without the keyword.Press Enter.
To reset the filter, click the clear icon (
), or delete the contents of the row filter field and press Enter.
To open the filter history, click the arrow icon near the ORDER BY keyword.
Set default sorting by a primary key
For the tables that have a numeric primary key, IntelliJ IDEA can sort the data by that key. IDE will send a new ORDER BY
query to the database each time you view the table data in data editor.
Press Ctrl+Alt+S to open settings and then select
.Under Data Sorting, select Sort tables by numeric primary key.
Select Ascending or Descending to set the sorting order.
Click OK.
![Sort table data by a numeric primary key Sort table data by a numeric primary key](https://resources.jetbrains.com/help/img/idea/2024.2/sort_table_data_by_numeric_primary_key.png)