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 8556505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:22:02+00:00 2026-06-11T15:22:02+00:00

I have a web page which has news data in one table. In many

  • 0

I have a web page which has news data in one table.

In many cases I use following SQL:

SELECT * FROM table ORDER BY insertDate DESC

to order.

ID|priority|insertDate
1 |NULL    |2012-09-16
2 |NULL    |2012-09-17
3 |NULL    |2012-09-18
5 |NULL    |2012-09-19
5 |NULL    |2012-09-20
4 |1       |2010-05-10 - this is way back in the future

But user wants to prioritize 1 news. And if I use

 SELECT * FROM table ORDER BY priority ASC ,insertDate DESC

It doesn’t work correctly, how do I must use ORDER to get result

ID|priority|insertDate
4 |1       |2010-05-10
1 |NULL    |2012-09-16
2 |NULL    |2012-09-17
3 |NULL    |2012-09-18
5 |NULL    |2012-09-19
5 |NULL    |2012-09-20
  • 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-06-11T15:22:03+00:00Added an answer on June 11, 2026 at 3:22 pm

    Use coalesce to set a valid value to Null priority rows:

    SELECT * 
    FROM table 
    ORDER BY 
       coalesce(priority,0) ASC ,
       insertDate DESC
    

    Edited

    Re-reading your question I see that right order is DESC and not ASC:

       coalesce(priority,0) DESC ,
    

    Also, notice @yshavit comment. To improve performance you can split query in two selects first one with not null values.

    Remember than when you create this new field you can set to it a default value, this will avoid coalesce and union:

    data_type [NOT NULL | NULL] [DEFAULT default_value]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one web page MyWebPage.aspx which while loading has to show data from
I have a web page which has many divs (listed like table rows), and
I have a web page which allow users to compose news articles. It has
I have a user profile page on my web app which has contact information.
I have a ASP.NET web application which has more than 100 pages. Each page
I have web page in PHP which displays all records in a table. I
I have a Webforms, AJAX-enabled web page which, when rendering large amounts of data,
I have a web page that displays dynamic data which changes every 2 seconds.
I have a web page which has a form at the top and a
I have Web page in share-point 2010 ,its has two web parts one for

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.