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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:00:31+00:00 2026-06-09T06:00:31+00:00

I have a problem understandint ORDER BY in MySQL . I have to sort

  • 0

I have a problem understandint ORDER BY in MySQL. I have to sort a table by 3 criteria

1 – first i want to sort by TYPE_OF_WORK so all data must be alphabetical, like

dech_rap_bus
dech_rap_bus
ger_dem_dech_bus
ger_dem_dech_bus
ger_dem_stp_pp
...

RESULT => http://sqlfiddle.com/#!2/b2a858/6

2 – second i want to sort by PROJECT_VERSION so all data must be alphabetical, but respecting the 1 criteria, like

dech_rap_bus            V123-V1234
dech_rap_bus            V300
ger_dem_dech_bus        V123-V1234  
ger_dem_dech_bus        V300
ger_dem_stp_pp          V123-V1234  

RESULT => http://sqlfiddle.com/#!2/b2a858/7

So 1 and 2 are working perfectly.

3 – and after this i want to sort by the column not_existing

RESULT => http://sqlfiddle.com/#!2/b2a858/5

and i don’t know what it really do, but i see no results … i just want that the

dech_rap_bus V300

where the NOT_EXISTING column is 1 to be at the end, and when are more of NOT_EXISTING = 1 to sort them all but at the end of the table.

I tought to myself that a UNION of 2 selects would help me

/* Selecting all data where  not_existing is not 1 or NULL ---> working good! */
(
    SELECT 
    * 
    FROM 
    atm_mti_view 
    WHERE 
    project_function='FRS01' AND 
    on_big_project_id = 12 AND
    (not_existing != 1 OR not_existing IS NULL)
    ORDER BY
    type_of_work ASC,
    project_version ASC
)

UNION

/* Selecting all data where  not_existing is 1 ---> working good! */
(
    SELECT 
    * 
    FROM 
    atm_mti_view 
    WHERE 
    project_function='FRS01' AND 
    on_big_project_id = 12 AND
    not_existing = 1
    ORDER BY
    type_of_work ASC,
    project_version ASC
)

but what this piece of code does, is putting the not existing dech_rap_bus at the end, good, but it messes up the version sorting, WHY???

SEE RESULT HERE => http://sqlfiddle.com/#!2/b2a858/8

Why is that? I just want to MERGE two select results, what i am doing wrong?

  • 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-09T06:00:32+00:00Added an answer on June 9, 2026 at 6:00 am

    If you do

    order by 
     (case when not_existing is null then 0 else not_existing end) desc
    ,type_of_work ASC,
    project_version ASC
    

    It will come first.

    your query is not ordering because you have different project value for dech_rap_bus

    TYPE_OF_WORK    PROJECT_VERSION 
    dech_rap_bus    V123-V1234  
    dech_rap_bus    V300
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem understanding how to save data in order to have an
I'm having a problem understanding the order of execution for the try-catch-finally. All the
I have problem understanding the order in which initialization happens. this is the order
I want to implement Hill cipher but I think I have a problem in
I have problem understanding what the return fibonacci( number-1 ) + fibonacci( number-2 )
I am new to vba and I have problem understanding the workbooks in vba
I have a problem understanding one style definition in Windows 8 metro apps. When
I seem to have a problem understanding how to conditionally test a boolean value
I think I have a problem in understanding the proper way of using MVC.
I am newbie to C#, and have a problem with understanding how should I

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.