Answer the question
In order to leave comments, you need to log in
How to write given sql query?
You want to display the entries sorted by the position field, however, the entries with the default value of position (which is 0) should be at the end of the list. That is, the list will be like this (field position): 1,2,3,4....0,0
Answer the question
In order to leave comments, you need to log in
ORDER BY `position` = 0, `position`
But indexes will not be used for such sorting.
sort not by field, I'm by function value from this field (fields)
for this in sql there is a wonderful case (in addition to ifnull/isnull/nullif etc.)
case when position=0 then 100500 else position end
p/s/ and by the way, it’s worth thinking about whether the default should be null and not 0 - then another aspect of the ordering will be revealed (in a number of dialects) just about null earlier / later than all
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question