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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:21:48+00:00 2026-05-16T08:21:48+00:00

I am trying to sort my database in some particular order, but I want

  • 0

I am trying to sort my database in some particular order, but I want all null’s at the end, so I am selecting all values with not null, and then selecting all values WITH null, and trying to join them with Union.. like:

SELECT * FROM preferences WHERE preferenceOrder IS NOT NULL 
                               ORDER BY preferenceOrder ASC
UNION

SELECT * FROM preferences WHERE preferenceOrder IS NULL 
                               ORDER BY preferences ASC

but the server throws an error:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'union'.

I cant find out what the error is though.. what is wrong with the sentence above?

thanks!

  • 1 1 Answer
  • 2 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-16T08:21:48+00:00Added an answer on May 16, 2026 at 8:21 am

    i think you should order by (case when preferenceOrder is null then 0 else 1 end), preferenceOrder instead of this union.

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

Sidebar

Related Questions

I'm trying to update an array element in Java. Some sort of a database
So I'm trying to get data from my sql database and sort it by
I am trying to sort pixel values of an image (example 80x20) from lowest
I'm trying to set a simple cron script to do some database updating, and
I am trying to sort articles by Today, This Week, This Month , All
So I'm trying to import some sales data into my MySQL database. The data
I'm thinking about trying MongoDB to use for storing our stats but have some
I am trying to create a website using some of the Razor functionality, but
I've been Googling for a while now trying to find some sort of solution
I'm trying to sort images using: http://jqueryui.com/demos/sortable/display-grid.html And then somehow submit the newly sorted

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.