I need to get data from MySQL table in ascending order but zero values come last and randomly
Right now this is my order by condition.This is not working
ORDER BY sortorder=0 RAND(),sortorder
I need to get data from MySQL table in ascending order but zero values come last and randomly
Right now this is my order by condition.This is not working
ORDER BY sortorder=0 RAND(),sortorder
Use conditional ordering
select *
from table
order by column > 0 desc, column asc, rand()
Add rand() at the end
Or you could use union
(select * from table where column > 0 order by column asc)
union all
(select * from table where column = 0 order by rand())
If you want to get data from mysql randomly and zero values come last. You may want to try the following:
SELECT * FROM table ORDER BY `column` = 0, rand();