Table column sorting based on NULL Value

Theva Deva

I want to sort column2 based on Column1 values. I want split column1 data based on NULL value. The final query result will be displayed on evaluating the values in the column1

   Column1    Column2 
    NULL         100
    NULL          60
    NULL          90
    10            22
    20            40
    05            35
    15            20
    40            10
    30            25
    20            30

Would become:

   Column1     Column2 
    20            40
    05            35
    20            30
    30            25
    10            22
    15            20
    40            10
    NULL         100
    NULL          90
    NULL          60

Thanks
Gurwinder Singh

You can use case in your order by clause like this:

Select * from t
Order by case when column1 is null then 1 else 0 end, column2 desc

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Eloquent sorting based on column value

Pandas: Sorting rows based on a value of a column

Sorting mat-table by column value

Lexicographical sorting of a Postgres table column based on values of another column

How to fill a NULL in a column with the value of a different line based on same id of a different table

Sorting table rows based on column class names using pure Javascript

Sorting the rows based on a particular column value using groovy

Linq filter based on null column value

Create a constraint based on column value to ensure not null

Sorting a list based on the average value of field under associated table

create table column based on another table column value in sql

Join table based on column value in SQL Server

Query table based on the value of another tables column

Expand table rows based on column value

Date Diff in the same column, based on the value of the table

Group items in a table based on value in column and count

Color table row based on column value

Return column headers based on value in table

change value in a column of a table based on a reference

Inner Join table based on column value

Extricating table based on the first unique column value

Insert rows into another table based on column value

Vuetify Table - rendering column value based on a condition

Get the value in the table that some column is null in MYSQL

Update Column value for all rows in Table where Column Value Is Null?

Sorting table rows by a column

Sorting array based on value

Sorting a group based on value

Problems in sorting a column by value