CodeIgniter Forums
Query Builder order by lenght - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Query Builder order by lenght (/showthread.php?tid=86172)



Query Builder order by lenght - pippuccio76 - 01-17-2023

Hi ,i have a field on db alphanumeric (A01,A20,A110) , to sorting properly  i must sort by LENGHT(nome)   , nome  but if i do this :
Code:
$scaffali_model->orderBy('LENGHT(nome)  ASC , nome ASC')->findAll();
I have this error : FUNCTION my_magazzinoes.LENGHT does not exist


RE: Query Builder order by lenght - ikesela - 01-17-2023

use SELECT to get the length, then can use the sort

select(' length(nome) as L')

orderBy('L asc')