Welcome Guest, Not a member yet? Register   Sign In
Order by string and number
#1

Hi in my db table i have this string  :

ser_14.000_1 ser_14.000_2 ser_14.000_3 ......ser_14.000_n

Using           $this->orderBy('macchina.seriale * 1 ','asc')  i have  ser_14.000_1 ser_14.000_2 ser_14.000_20 ser_14.000_3 .

HOw can i order by final number  ?
Reply
#2

(This post was last modified: 05-15-2023, 01:02 AM by JustJohnQ. Edit Reason: error in query corrected )

Using plain SQL you can use:

Code:
SELECT * FROM table ORDER by SUBSTRING_INDEX(macchina.seriale, '_' , -1) * 1 ASC
Reply




Theme © iAndrew 2016 - Forum software by © MyBB