Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

A tough one - might get better responses on a mysql forum...

SELECT field+0<>0, field+0, field FROM `table`  ORDER BY field+0<>0 DESC, field+0, field; 
0
Solution

When I needed to do something similar in the past I just stuck in an extra field for sorting. When a record is saved parse the string and left pad all numbers to 6? digits with zeros. save that in the sort field and job done.

0

Thanks @kpzani; that's what I ended up doing. Not the cleanest, but it gets the job done!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.