CodeIgniter Forums
SQL Order By, excluding 'the' - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: SQL Order By, excluding 'the' (/showthread.php?tid=10053)



SQL Order By, excluding 'the' - El Forum - 07-17-2008

[eluser]bradya[/eluser]
Hi Guys,

I know this isn't a CI specific question, but though you might have some ideas on it. I am fetching a list of bands from a mysql table, and ordering by band name. Problem being that any band beginning with 'the' eg. 'The Sleepy Jackson' is automatically put as a 'T' rather than 'S'.

So, does anyone know of a way to order sql results, but to exclude words like 'the', kind of like stopwords in a full-text search I guess...


SQL Order By, excluding 'the' - El Forum - 07-17-2008

[eluser]xwero[/eluser]
Code:
$this->db->order_by("REPLACE(bandname,'The ','')");



SQL Order By, excluding 'the' - El Forum - 07-17-2008

[eluser]bradya[/eluser]
[quote author="xwero" date="1216323913"]
Code:
$this->db->order_by("REPLACE(bandname,'The ','')");
[/quote]

Thanks Xwero! Worked like a charm.