Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:36:26+00:00 2026-05-22T14:36:26+00:00

Need a postgresql query which return null value at the end of the non-null

  • 0

Need a postgresql query which return null value at the end of the non-null value irrespective of the Ascending/Descending Order.

For ex:- I have a column say purchase_price having values 1, 5, 3, 0, null, null

Then for ORDER BY purchase_price ASC It should return

0
1
3
5
null
null

and for ORDER BY purchase_price DESC It should return

5
3
1
0
null
null

I need generalise solution which i can able to apply for the 'boolean', 'float', 'string', 'integer', 'date' Datatype

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:36:26+00:00Added an answer on May 22, 2026 at 2:36 pm

    order by supports nulls first/last. By default asc gets nulls last and desc gets nulls first. You can override them for each column:

    order by col1 desc nulls last, col2 desc nulls first, etc
    

    An extra note on this: the underlying reason is that nulls they get placed at the end of the btree index. In PostgreSQL 9.0, order by col desc nulls last is optimized to split the index scan in two (reverse scan on not null rows, followed by null rows). This was not the case in the original version where it was added (8.4 if memory serves); the latter proceeds to do a seq scan of the whole table followed by a quicksort). And older versions do not support the feature at all. So be wary of using it in anything but recent versions of PostgreSQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In PostgreSQL I have a query like the following which will delete 250k rows
I need to order a select query using a varchar column, using numerical and
I need to learn about Postgresql. I'm trying to branch an application framework which
I need to setup my PostgreSQL DB's text encoding to handle non-American English characters
I'd need advice on following situation with Oracle/PostgreSQL: I have a db table with
I have a name of table or view in PostgreSQL database and need to
I have a query that needs to return results that are NOT matched in
Is it possible to have selective queries in PostgreSQL which select different tables/columns based
I have a query which takes a long time and I want to optimize
I'm trying to execute a postgresql query which returns a large result: connection.setAutoCommit(false); st

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.