+ Reply to Thread
Results 1 to 2 of 2

Thread: place null entries in the end

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    28

    place null entries in the end

    If I have the following entries in my database and this is what i get using order by :
    1 [null]
    2 [empty string]
    3 Alpha
    4 Bravo
    5 Charlie

    But i actually want the below :
    3 Alpha
    4 Bravo
    5 Charlie
    1 [null]
    2 ''

    How can I order the rows with names to the front when using ORDER BY?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Use that :
    Code:
    ORDER BY 
        CASE 
        WHEN Name IS NULL THEN 1 
        WHEN Name = ''    THEN 2 
        ELSE 3 
        END DESC, 
        Name ASC

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts