I have understandint ORDER BY problem in MySQL . I need to sort a table by three criteria
1 - first I want to sort by TYPE_OF_WORK , so all data should be in alphabetical order, for example
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 the data should be in alphabetical order, but in accordance with 1 criterion, for example
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 work fine.
3 - and after that I want to sort by not_existing column
RESULT => http://sqlfiddle.com/#!2/b2a858/5
and I donβt know what heβs actually doing, but I donβt see the results ... I just want
dech_rap_bus V300
where the column NOT_EXISTING 1 is at the end, and when more than NOT_EXISTING = 1 >, to sort them all, except at the end of the table.
I tried myself that UNION of 2 options will help me
( 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 ( 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 put the non-existent dech_rap_bus at the end, fine, but it messed up the version sorting, WHY ???
CM. RESULT HERE => http://sqlfiddle.com/#!2/b2a858/8
Why? I just want MERGE to select two results, what am I doing wrong?
Thanks.